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

How do I make this special wait script for my vehicle seat?

Asked by 6 years ago

How do I make this special wait script? I'm trying to make it so that if the vehicle seat this script is in does not move faster than 10 magnitude for more than 20 seconds, its joints break.

But I think I have made a script that if the speed is less than 10 magnitude for even a second, it will wait 20 seconds an still carry out the activity, which is not what I want.

I know this is no where near right, but I do not know what I am doing.

if script.Parent.Velocity.Magnitude < 10 
then wait(20)
    script.Parent:BreakJoints()


    end

1
I have provided an answer to your problem. Let me know if your problem is solved. RAYAN1565 691 — 6y

2 answers

Log in to vote
1
Answered by
RAYAN1565 691 Moderation Voter
6 years ago
Edited 6 years ago
while true do
    wait()
    if script.Parent.Velocity.Magnitude < 10 then -- The "then" needs to be on the same line as "if."
        for i=0, 21, 1 do
            magnitude = script.Parent.Velocity.Magnitude
            wait(1)
            i = i+1
            if magnitude < 10 and i >= 20 then
                script.Parent:BreakJoints()
            elseif magnitude >= 10 or i >= 20 then
                break
            end
        end
    end
end

Try this.

0
Actually, magnitude is deprecated it should be Magnitude. User#19524 175 — 6y
1
@incapaz when was that said? RAYAN1565 691 — 6y
0
When something is deprecated it is either striked or hidden, magnitude is hidden https://gyazo.com/e5a0a889b40600e235d5f7db9b47be7a User#19524 175 — 6y
1
I edited my answer to use the non-deprecated form. Thanks for catching that! I haven't checked out the deprecated list; I should take a look. RAYAN1565 691 — 6y
0
Thank you so much! TheBeaver101 28 — 6y
Ad
Log in to vote
1
Answered by
saenae 318 Moderation Voter
6 years ago

I don't have a whole lot of time on my hands today, so I can't properly explain it all right now, write a comment if anything doesn't make sense/it doesn't work. Sorry about that.

local startTime = tick(); -- make timer
while wait(1) do
    if(script.Parent.Velocity.Magnitude >= 10) then
        startTime = tick(); -- reset timer when moving faster than 10 studs/second
    elseif(tick()-startTime >= 20) then
        script.Parent:BreakJoints();
    end
end
0
For the record, I waited 1 in the loop primarily for the sake of performance, you can wait however long you like. saenae 318 — 6y
0
No, don't use wait() as a condition. User#19524 175 — 6y

Answer this question