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

How do you detect if a part's position has been changed?

Asked by
drew1017 330 Moderation Voter
9 years ago

Because as far as I know there isnt a changed event for it. Ive tried some while loop updaters but they were too laggy, and im stumped on what other options i might have. Could someone tell me how to do this?

1 answer

Log in to vote
0
Answered by 9 years ago

Use Changed. This even fires whenever property of an instance is changed, like position!

script.Parent.Changed:connect(function(pos)--You need a function
    if pos == "Position" then --if pos is position then
        print("PartMoved")
    end
end)

If you want to record the old position and the new one try this script:

local oldpos = script.Parent.Position
local newpos

script.Parent.Changed:connect(function(pos)
    if pos == "Position" then --if pos is position then
        if newpos ~= nil then
            oldpos = newpos
        end
        newpos = script.Parent.Position
    end
end)

Hope it helps!

Ad

Answer this question