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.
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