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

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

Asked by 6 years ago

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

0
I like this question. Hopefully someone is able to help you. DinozCreates 1070 — 6y
0
nein TheluaBanana 946 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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

place in part that u want to monitor

01local part = script.Parent
02 
03local frames = 0
04 
05while true do
06    local p1 = part.Position
07 
08    wait(1 / 60)
09 
10    if p1 == part.Position then
11        frames = frames + 1
12 
13        print(frames)
14 
15    else
16        frames = 0
17    end
18end

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:

01local part = script.Parent
02local frames = 0
03 
04local changed = false
05 
06function addFrames()
07    while true do
08        if part.Anchored == false and changed == false then
09            wait(1 / 60)
10 
11            frames = frames + 1
12 
13            print(frames)
14 
15        else
View all 37 lines...
0
.Changed doesnt fire on busy properties such as position Gey4Jesus69 2705 — 6y
Ad

Answer this question