How do I fix this?

Im trying to make a long jump script, but I noticed a few problems.

I can long jump while in the air and in the state of “Long Jump”, I can spam long jump to propel in the air more farther, and It looks a bit glitchy when I do spam the space key while holding space.

You can test it here, so how do I fix it?

--\\ Variables //--
repeat task.wait() until game.Players.LocalPlayer

local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local Character = game.Players.LocalPlayer.Character
local IsOn, JumpLength = nil, .3
local JumpAnimation = Character.Humanoid:LoadAnimation(RS.LongJumpAnimation.LongJumps)
local DView = 70
local Table = {}

local root = script.Parent.PrimaryPart
local humanoid = root.Parent:WaitForChild("Humanoid")
local state = " "

local stateText = script.Parent:WaitForChild("Head"):FindFirstChildOfClass("BillboardGui").TextLabel

--\\ Functions //--

function speedWatch(speed)
	if speed == 24 then
		local boostVal = 1.25
		return boostVal
	elseif speed == 16 then
		local boostVal = 1.15
		return boostVal
	else
		local boostVal = 1
		return boostVal
	end
end

humanoid.Running:Connect(function(speed)
	if speed > 0 then
		state = "RUNNING"
	elseif speed == 0 then
		state = "IDLE"
	end
end)

humanoid.Jumping:Connect(function()
	state = "JUMPING"
end)



UIS.InputBegan:Connect(function(Input, IsTyping)
	if state == "RUNNING" and state ~= "IDLE" or state ~= "JUMPING" or state ~= "LONG_JUMP" then
		if IsTyping then return end
		if UIS:IsKeyDown(Enum.KeyCode.LeftShift) and UIS:IsKeyDown(Enum.KeyCode.Space) and humanoid.Running then
			state = "LONG_JUMP"
			local speed = Character.Humanoid.WalkSpeed
			if IsOn then return end
			IsOn = true

			local speedBoost = speedWatch(humanoid.WalkSpeed)

			JumpAnimation:Play()

			humanoid.Jump = false humanoid.JumpPower = 0
			root:ApplyImpulse(root.CFrame.LookVector * (1220 * speedBoost))
			workspace.Gravity = 98.1
			root:ApplyImpulse(root.CFrame.YVector * (500 * speedBoost))
			task.wait(0.25)
			workspace.Gravity = 196.2
			humanoid.Jump = false humanoid.JumpPower = 50


			-- Tween
			local Information = TweenInfo.new(JumpLength, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut,0,true,0)

			TweenService:Create(game.Workspace.CurrentCamera,Information, {FieldOfView = DView + 15}):Play()

			task.wait(JumpLength)
			JumpAnimation:Stop()
			IsOn = nil
		end
	end
end)

--\\ Loops //--

while task.wait() do
	stateText.Text = "STATE: "..state
	print(state)
end

Add a cooldown. Maybe that will work

local cooldown = false
local cooldowntime = 3
UIS.InputBegan:Connect(function(Input, IsTyping)
	if state == "RUNNING" and state ~= "IDLE" or state ~= "JUMPING" or state ~= "LONG_JUMP" then
		if IsTyping then return end
		if UIS:IsKeyDown(Enum.KeyCode.LeftShift) and UIS:IsKeyDown(Enum.KeyCode.Space) and humanoid.Running then
            if cooldown then return end
            cooldown = true
			state = "LONG_JUMP"
			local speed = Character.Humanoid.WalkSpeed
			if IsOn then return end
			IsOn = true

			local speedBoost = speedWatch(humanoid.WalkSpeed)

			JumpAnimation:Play()

			humanoid.Jump = false humanoid.JumpPower = 0
			root:ApplyImpulse(root.CFrame.LookVector * (1220 * speedBoost))
			workspace.Gravity = 98.1
			root:ApplyImpulse(root.CFrame.YVector * (500 * speedBoost))
			task.wait(0.25)
			workspace.Gravity = 196.2
			humanoid.Jump = false humanoid.JumpPower = 50


			-- Tween
			local Information = TweenInfo.new(JumpLength, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut,0,true,0)

			TweenService:Create(game.Workspace.CurrentCamera,Information, {FieldOfView = DView + 15}):Play()

			task.wait(JumpLength)
			JumpAnimation:Stop()
			IsOn = nil
            task.wait(cooldowntime)
            cooldown = false
		end
	end
end)

It might be because you are semantically writing your conditional incorrectly?

state ~= "JUMPING" or state ~= "LONG_JUMP"

Let’s say that the state is currently "LONG_JUMP".
When it goes through this conditional statement, it will instantly go through because state is not "JUMPING". Instead try:

state ~= "JUMPING" and state ~= "LONG_JUMP"

Change

if state == "RUNNING" and state ~= "IDLE" or state ~= "JUMPING" or state ~= "LONG_JUMP" then

To

if state == "RUNNING" and state ~= "IDLE" and state ~= "JUMPING" and state ~= "LONG_JUMP" then