How to disable cooldown when player is sitting or swimming

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
2 Likes

Fixed, I needed to remove the

char.Humanoid.FloorMaterial == Enum.Material.Air ← (and remove the if statement wrapping it)

at the start as it was the first condition triggered, and when swimming and sitting, they foot would only be facing the air so I guess that makes sense.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.