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

How do I wait until a specific event occurs?

Asked by 5 years ago
Edited 5 years ago

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.

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

That's all really. Thanks.

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. VoidKeyword 111 — 5y
0
It's also removed, as I last used Seats I remembered you being able to do that. killerbrenden 1537 — 5y

2 answers

Log in to vote
2
Answered by 5 years ago

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

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

01local currentChar
02 
03script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
04    if script.Parent.Occupant ~= nil then
05        local occupant = script.Parent.Occupant
06        currentChar = occupant.Parent
07        currentChar.Humanoid.WalkSpeed = 0
08    elseif script.Parent.Occupant == nil then
09        currentChar.Humanoid.WalkSpeed = 16
10    end
11end)

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!

Ad
Log in to vote
0
Answered by
Kurcha 33
5 years ago

Use this:

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

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

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. VoidKeyword 111 — 5y

Answer this question