Check characters position [SOLVED]

  • #1, z red363Monday, 05. June 2023, 06:04 hodinky A year 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

    Fanoušek fóra

    101 Posts


  • #2, z afrlmeMonday, 05. June 2023, 23:52 hodinky A year 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.


    Imperátor

    7285 Posts

  • #3, z red363Tuesday, 06. June 2023, 13:57 hodinky A year 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!

    Fanoušek fóra

    101 Posts