Especially how to disable it for when the player is swimming
Hey, I made a jump cool down script which works fine, however, I need it to not respond to when the player is sitting or swimming as so they can actually get out the pool/seat. I used UserInputService with Jump request and ChangeStateEnabled for when the jumps are allowed vs when they are not respectively.
local jumpCooldown = 3.0
local UserInputService = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local Jumped = false
UserInputService.JumpRequest:Connect(function()
local char = plr.Character -- some may place this script in StarterPlayer...
print(char.Humanoid:GetState())
if not Jumped then
if char.Humanoid.FloorMaterial == Enum.Material.Air then return
elseif char.Humanoid:GetState() == Enum.HumanoidStateType.Seated then
char.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
print("Can jump when seated")
elseif char.Humanoid:GetState() == Enum.HumanoidStateType.Swimming then
char.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
print("Can jump when swimming")
else
Jumped = true --Making it true do it does not loop twice
char.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping) --Making the character jump
task.wait(jumpCooldown)
Jumped = false
end
else
char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
end)
Thank you in advance