I want to make it so the player cannot leave a seat for my game, But I don’t know how to do it.
set jumpower to 0 or soemthing i think.
Do a check for the seat Occupant input and see if they jump. If they do then cancel the jump.
You can set the Humanoid SetStateEnabled to enable/disable the HumanoidStateType.
I think if you set the JumpPower to 0 as @DeEchteBelg said, the player won’t jump up, but I think it’ll still remove the SeatWeld and the player will fall off.
How do I do that?
As @Scottifly said, it’s a good idea to track the seat.Occupant
changes and cancel the jump or re-seat the player. Also important is to prevent exploiters from standing up anyway by changing the JumpPower/JumpHeight or re-enabling the jumping state.
My first idea was to use humanoid:SetStateEnabled
too, however, it appears to be the type of the state that cannot be applied by the server. So I think seat:Sit(humanoid)
is not a bad alternative. On top, we reduce JumpHeight.
Example:
local Players = game:GetService("Players")
local seat = workspace.Seat
local occupantValue = seat:WaitForChild("Occupant")
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
if Players:GetPlayerFromCharacter(seat.Occupant.Parent) then
occupantValue.Value = seat.Occupant
seat.Occupant.JumpHeight = 0
end
else
if not occupantValue.Value then return; end
if occupantValue.Value.Health <= 0 then
occupantValue.Value = nil; return;
end
task.wait(.1)
seat:Sit(occupantValue.Value)
end
end)
I used an ObjectValue
inside the seat named “Occupant” to store the humanoid (could also use attributes, but they cannot point to instances).
The script is yielding indefinitely now on that line.
You need that ObjectValue named Occupant
inside the seat in my case.
It works, now I am glued to my seat!
Now I just need to figure out how to get off… (Seriously though)
So you need to use some kind of signal in your script to disable the seat weld and allow the player to jump again?
What in your game is going to be the ‘cause’ of the player to be able to leave the seat? Use that as your signal.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.