I have been attempting to make a system, where if a player is seated and a specific BoolValue is true, then the player’s JumpPower is set to 50, but if the value is false, then that player’s JumpPower will be set to 0.
I’ve got the if statements all working, but my only struggle is getting the JumpPower part to work.
This is a script that is placed inside of the seat:
local seat = script.Parent
local LeftDoor = game.Workspace.EurekaTrainSystemV2e.Train["Type 310"].DoorL
local RightDoor = game.Workspace.EurekaTrainSystemV2e.Train["Type 310"].DoorR
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local Char = seat.Occupant.Parent
local hum = Char.Character:WaitForChild("Humanoid")
if LeftDoor.Value == true then
hum.JumpPower = 50
print("Left door open, can stand")
elseif RightDoor.Value == true then
hum.JumpPower = 50
print("Right door open, can stand")
else
hum.JumpPower = 0
print("No doors open, cannot stand")
end
end)
First off, you tried getting the character from the character. This is the cause of the second error.
The first error is because when the player leaves the seat there is no occupant, try this script:
local seat = script.Parent
local LeftDoor = game.Workspace.EurekaTrainSystemV2e.Train["Type 310"].DoorL
local RightDoor = game.Workspace.EurekaTrainSystemV2e.Train["Type 310"].DoorR
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if not seat.Occupant then return end
local Char = seat.Occupant.Parent
local hum = Char:WaitForChild("Humanoid")
if LeftDoor.Value == true then
hum.JumpPower = 50
print("Left door open, can stand")
elseif RightDoor.Value == true then
hum.JumpPower = 50
print("Right door open, can stand")
else
hum.JumpPower = 0
print("No doors open, cannot stand")
end
end)