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

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

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 comment

1

I have provided an answer to your problem. Let me know if your problem is solved.

2 answers

✓ Accepted answer
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.

5 comments

0

Actually, magnitude is deprecated it should be Magnitude.

1

@incapaz when was that said?

0

When something is deprecated it is either striked or hidden, magnitude is hidden https://gyazo.com/e5a0a889b40600e235d5f7db9b47be7a

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.

0

Thank you so much!

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

2 comments

0

For the record, I waited 1 in the loop primarily for the sake of performance, you can wait however long you like.

0

No, don't use wait() as a condition.

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