Check characters position [SOLVED]

  • #1, by red363Monday, 05. June 2023, 06:04 12 months ago
    Hello!

    I'm trying to dynamically track the position of one character relative to another so that something happens. In definition script:

    please tell me why it works like this?

    function checkCharPos()

      if game.CurrentCharacter.Position.x == Characters["name"].Position.x then

      print("yes") 

      else

      print("no") 

      end

    end

    registerEventHandler("mainLoop", "checkCharPos") this does not work:

    And this does not work:

    local pos1 = game.CurrentCharacter.Position.x
    local pos2 = Characters["name"].Position.x

    function checkCharPos()

      if pos1 == pos2 then

      print("yes")

      else

      print("no")

      end

    end

    registerEventHandler("mainLoop", "checkCharPos")

    ???

    Thank you

    Forum Fan

    101 Posts


  • #2, by afrlmeMonday, 05. June 2023, 23:52 12 months ago
    The second one is probably not working because you are storing the value in a variable outside of the function & thus it's not actually updating it each time, I think.


    Imperator

    7281 Posts

  • #3, by red363Tuesday, 06. June 2023, 13:57 12 months ago
    The second one is probably not working because you are storing the value in a variable outside of the function & thus it's not actually updating it each time, I think.



    O, yes, thank you!

    Forum Fan

    101 Posts

Write post