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 wait until a specific event occurs?

Just two lines of code, I want it to keep the walkspeed at 0 until the user is sitting down, then it changes it back to 16. Here's the code so you can get the idea of what I'm trying to do.

Player.Character.Humanoid.Walkspeed = 0
--I want to wait until the seat is occupant is humanoid.

That's all really. Thanks.

2 comments

0

@killerbrenden That wouldn't fit my needs, I want to set the player's walkspeed once they are teleported to the seat, and set it back to normal once they sit.

0

It's also removed, as I last used Seats I remembered you being able to do that.

2 answers

✓ Accepted answer

So, put a ServerScript in the seat that you want it work in.

And write this, I'll explain the code under it.

local currentChar

script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
	if script.Parent.Occupant ~= nil then
		local occupant = script.Parent.Occupant
		currentChar = occupant.Parent
		currentChar.Humanoid.WalkSpeed = 0
	elseif script.Parent.Occupant == nil then
		currentChar.Humanoid.WalkSpeed = 16
	end
end)

This will check whenever the occupant value changes, and their is a variable that whenever a player is sitting on it, their character is referenced as currentChar. Whenever they sit down, their walkspeed changes to 0, and whenever they get up, it get's set back to 16.

Hope this helped! Don't forget to select this as the answer if this worked for you!

Use this:

repeat wait(1) until Player.Character.Humanoid.SeatPart ~= "" -- waits in intervals of one second

repeat wait() can be more than 1 second, or instant

1 comment

0

This works, but the issue is that sometimes when a player tries to sit, the seat is being locked, so it isn't very ethical.

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