Hi! I currently have a script that when a player sits in a seat, it checks if they’ve been assigned as a staff member. If they haven’t, then it will simply jump them out of the seat. However, the jumping part doesn’t work.
My code to jump the character is:
player.Character.Humanoid.Jump = true
By the way, it is not because the character/humanoid/player is nil as there are no errors in the output. I’ve also tried logging something in the console if the player is not a staff, and it logs it but it does not jump the player.
local gui
local allowedRoles = {"GA", "Flight Host"}
function giveTool(weldChild)
local findHuman = weldChild.Part1.Parent:FindFirstChild("Humanoid")
if findHuman ~= nil then
local player = game.Players:GetPlayerFromCharacter(findHuman.Parent)
if (player ~= nil) then
local staffRole = game.ServerStorage.Staff:FindFirstChild(tostring(player.UserId))
if staffRole ~= nil and table.find(allowedRoles, staffRole.Value) then
gui = script.Parent["System"]:Clone() -- Change toolname to what tool you want to be given
gui.Parent = player.PlayerGui
gui.Seat.Value = script.Parent
else
print("yes")
print(player.Character.Name)
player.Character.Humanoid.Jump = true
end
end
end
end
function removeTool()
if (gui ~= nil) then
gui:Destroy()
end
end
script.Parent.ChildAdded:Connect(giveTool)
script.Parent.ChildRemoved:Connect(removeTool)
And by the way, this is a modified version of the original script.
Oh you’re forcing them out of a vehicle? Then keep it.
local seat = script.Parent
local occupant
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
print(seat.Occupant.Parent) --prints player's name
--code
else
--code
end
end)
I don’t think that using a repeat loop is a good idea to wait for the character, there is a function that yields until the character exists, instead of the loop you can do
local character = player.Character or player.CharacterAdded:Wait()`
local seat = script.Parent
local occupant
local allowedRoles = {"GA", "Flight Host"}
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
occupant = seat.Occupant.Parent
local player = game.Players:GetPlayerFromCharacter(occupant)
if (player ~= nil) then
local staffRole = game.ServerStorage.Staff:FindFirstChild(tostring(player.UserId))
if staffRole ~= nil and table.find(allowedRoles, staffRole.Value) then
local GUI = seat.System:Clone()
GUI.Parent = player.PlayerGui
GUI.Seat.Value = seat
else
player.Character.Humanoid.Jump = true
end
end
else
local GUI = game.Players:GetPlayerFromCharacter(occupant).PlayerGui:FindFirstChild("System")
if GUI then
GUI:Destroy()
end
end
end)