Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

BodyPosition Position not working well, thus ReachedTarget not triggering; serious consequence!?

Asked by
Ribasu 127
5 years ago
Edited 5 years ago

I have a part and I am inserting into it a BodyPosition force. So I am expecting the part to move to that BodyPosition. With this BodyPosition, I have attached a ReachedTarget event which will change the position's BodyPosition to 2 studs up in the Y dimension, so the part will move up and later move up again - this process should repeat ad infinitum. Here is the code of this implementation:

local part = Instance.new("Part")
part.Parent = workspace
part.CanCollide = false

local partBodyPosition = Instance.new("BodyPosition")
partBodyPosition.Parent = part


partBodyPosition.ReachedTarget:connect(function()
    print('target reached')
    print('changing position')
    partBodyPosition.Position = partBodyPosition.Position + Vector3.new(0,2,0)
end)



partBodyPosition.Position = Vector3.new(10,10,10) -- set the BodyPart's Position. Expected behaviour is that ReachedTarget connected event will execute as soon as this line's position is reached

However, there's quite a few big problems in this situation. First of all, the event is not being triggered. There's a good reason why it's not: the part is intead getting an approximate value of 9.7,9.7,9.7 rather than 10,10,10, so the position is never truly reached and therefore, event is not triggered. How can I over come this?

Second, when I move the part via GUI, the event does eventually trigger. But it only gets triggered once, I expect such an event to keep triggering infinitely (reach Position -> trigger event -> reach Position -> trigger Event -> reach Position -> ....).

Answer this question