Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I detect if an unanchored part is unable to move because it is crushed in place?

Is there some event that can help detect if the part is not moving not because it is anchored, but because it is stuck in place by friction or unable to feasibly move elsewhere

2 comments

0

I like this question. Hopefully someone is able to help you.

0

nein

1 answer

here is an easy way, though i cant assure u it will not lag ur game:

place in part that u want to monitor

local part = script.Parent

local frames = 0

while true do
	local p1 = part.Position
	
	wait(1 / 60)
	
	if p1 == part.Position then
		frames = frames + 1
		
		print(frames)
		
	else
		frames = 0
	end
end

what this does is it forever checks if the part's position, waits for a frame, then compares the previous position to the new position, all while checking if the part is uncanchored as well. If the 2 positions are the same, then it will add 1 to the frames which the part is inactive for.

Another way would be to use the propertyChanged thing, very much like the first one, but not as good in my eyes due to some inconsistencies with the thing:

local part = script.Parent
local frames = 0

local changed = false

function addFrames()
	while true do
		if part.Anchored == false and changed == false then
			wait(1 / 60)
			
			frames = frames + 1
			
			print(frames)
			
		else
			frames = 0
			
			break
		end
	end
end

part:GetPropertyChangedSignal("Position"):Connect(function()
	changed = true
	
	wait(1 / 10)
	
	changed = false
	
	wait(1 / 10)
	
	if changed == false then
		addFrames()
	end
end)

addFrames()

1 comment

0

.Changed doesnt fire on busy properties such as position

This discussion is preserved as it was. New answers, comments, and votes are closed.