I`m trying to make a script so you cannot sit unless you are the owner of that seat. Is there anything that can help me do that?
Any hint/help appreciatted.
I`m trying to make a script so you cannot sit unless you are the owner of that seat. Is there anything that can help me do that?
Any hint/help appreciatted.
i don’t think you need detect when the player sits for what your doing, instead you could utilize the Disabled property and just disable the seat locally if the player does not own the seat
if you needed to detect when the player sits you can used what was mentioned above or use HumanoidStateType
A seat has a “Occupant” property.
You can make a function to detect whenever the occupant is changed like this;
Seat.Changed:Connect(function()
end)
Next you can check to see if the Occupant is not equal to the player
if Seat.Occupant.Parent.Name ~= "PlayerNameHere" then
end
After that you can jump the player if it doesn’t equal it. First you should make a value that is equal to the player and a value equal to the character
local PlayerToJump = game.Players:FindFirstChild(Seat.Occupant.Parent.Name)
local Character = PlayerToJump.Character or PlayerToJump.CharacterAdded:Wait()
Finally let’s jump them. We need to add a small wait() before though to make sure that the player is completely seated or else the jump will be set to true, but the seat will still sit the player down. Usually a wait of .1 is long enough.
wait(.1)
Character.Humanoid.Jump = true
The final piece of code should be;
Seat.Changed:Connect(function()
if Seat.Occupant.Parent.Name ~= "PlayerNameHere" then
local PlayerToJump = game.Players:FindFirstChild(Seat.Occupant.Parent.Name)
local Character = PlayerToJump.Character or PlayerToJump.CharacterAdded:Wait()
wait(.1)
Character.Humanoid.Jump = true
end
end)
Edit; I forgot to add a check to see if the seat’s occupant is not nil.
if Seat.Occupant ~= nil then
end
All in all, the final piece of code should be;
Seat.Changed:Connect(function()
if Seat.Occupant ~= nil then
if Seat.Occupant.Parent.Name ~= "PlayerNameHere" then
local PlayerToJump = game.Players:FindFirstChild(Seat.Occupant.Parent.Name)
local Character = PlayerToJump.Character or PlayerToJump.CharacterAdded:Wait()
wait(.1)
Character.Humanoid.Jump = true
end
end
end)
Thanks for your help! I`ll check that rn.
Okie, also I forgot to mention “Seat” should be a value equal to the Seat. Like
local Seat = script.Parent -- If the script was placed inside the Seat
Ye i guessed so I think it works thx