How would I check if a part's CFrame/Position changed without it being taxing

How would I check if a part’s CFrame/Position changed without it being taxing, EG: a while do loop or a repeat loop, just any loop.

I’m checking if the position of hundreds of items has changed all at once and it’s just not sustainable to do hundreds of loops for this, I crash when exiting playtest if I use loops

TLDR; I need to check if the position of a part has changed without using loops.

--ServerScript in ServerScriptService
local part = Instance.new("Part")
part.Size = Vector3.new(4,4,4)
part.Position = Vector3.new(0,5,0)
part.Anchored = true
part.Parent = workspace

part:GetPropertyChangedSignal("Position"):Connect(function()
	print("part moved to", part.Position)
end)

while true do task.wait(1)
	part.Position = part.Position + Vector3.new(1,0,0)
end

My whole test.

Part only has one GetPropertyChangedSignal connection, so there’s no continuous polling or loops checking positions. Hundreds of parts won’t tax the engine much, because Roblox is just listening for the event. This test has a loop just to test the Connect function..

3 Likes

GetPropertyChangedSignal on Position doesn’t work from what I’ve tried but I’ll try this since there’s no harm

1 Like

It works.. and it’s just what you’re looking for.

1 Like