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 5 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 — 5y
0
nein TheluaBanana 946 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 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

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()
0
.Changed doesnt fire on busy properties such as position Gey4Jesus69 2705 — 5y
Ad

Answer this question