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 4 years ago
Edited 4 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.

Player.Character.Humanoid.Walkspeed = 0
--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 — 4y
0
It's also removed, as I last used Seats I remembered you being able to do that. killerbrenden 1537 — 4y

2 answers

Log in to vote
2
Answered by 4 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.

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!

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

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

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 — 4y

Answer this question