Hi! I’m trying to make a script “detect” when a part has moved out of its origional positiion, but it doesn’t seem to be working. Here is what I have so far:
local part = script.Parent
part.Position = Vector3.new(-30, 17, -15)
if part.Position ~= Vector3.new(-30, 17, -15) then
print("Block fell")
end
It seemed pretty simple to me. Basically, I put a part at position -30, 17, -15. After that, I made an If → Then statement that said if the block is not equal to its original position, then it should print “Block fell” in the script analysis bar. However, that doesn’t seem to be working whenever I move it (it’s unanchored), and was wondering if anyone had a fix. Thanks
All you do is check it once when the game starts. You should use GetPropertyChangedSignal on the Position property, check if the position changed to something different than its original position, and then you can disconnect the connection.
local part: BasePart = script.Parent
local runService: RunService = game:GetService("RunService")
local connection = nil
local currentPosition = part.Position
connection = runService.Heartbeat:Connect(function()
if (currentPosition ~= part.Position) then
print("Fell")
connection:Disconnect()
end
end)
Sorry for the late response. Thanks for your help! I have one question though, what does the “connection” have to do with this? I’m not script-savvy, so I would really like to know!