Alright, so long story short I have a game in which I want players to not be able to jump, normally. Now, I've ran into the situation in which I would like to add benches/seats in which the players can well, sit... The catch is that if players do sit, and jumping is disabled, they'd have to reset in order to be able to move again.
Now obviously, I do not want this, instead what I tried to do was make a script that detects when the player sits, which then allows the player to jump and after they do disables it again. I've finished 2/3's of that goal, I've made my bench and inside it is a script that detects when a player sits on it, I've also been able to re-enable jumping once the script detects that a player is sitting, however the part in which I'm having issues with is re-disabling the jump after the player jumps/stands up again, and currently the output is blaming my variables for being nil... Here, take a look at the script:
local seat = script.Parent
local character = nil
local player = nil
print("Debugging- ESU Script initialized.")
seat.Changed:connect(function(property)
if property ~= "Occupant" then return end
local occupant = seat.Occupant
if occupant then
print("Debugging- 'if occupant' check went thru.")
local character = occupant.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
player.PlayerScripts.DisableJumping.Disabled = true
character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
print("Debugging- 'If player' check went thru.")
end
else
-- Must fix this part V
player.PlayerScripts.DisableJumping.Disabled = false
character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
end)
So, everything works up until "else", the output tells me that the "player" variable is nil, but the thing I don't understand is why since I set its value prior to that. If anybody knows what is the mistake I'm making I'll appreciate some input, and if there's a fix/way to do what I'm aiming for please let me know, any help is appreciated, thanks in advance!
