I am trying to make a script that allows the player to do a short hop by quickly releasing the spacebar after pressing it, or to do a full hop by holding it down. To track the spacebar I have a BoolValue called "space". However, this BoolValue is laggy and doesn't respond exactly as it should. This makes doing a full hop unpredictable and hard to do. I have another BoolValue for the w key which tracks the w key for something else, and it works perfectly fine. What's the problem here?

function onKeyDown(key)
	if key:byte() == 48 and running.Value == false and grounded.Value == true and script.KEYS.w.Value == true then
		running.Value = true
		pl.Character.Humanoid.WalkSpeed = runspeed.Value
	end
	if key == "w" then
		script.KEYS.w.Value = true
	end
	if script.debugs.Disabled == false then
	print(key:byte())
	end
	if key:byte() == 32 and grounded.Value == true and jumpsquat.Value == false then
		print("jump")
		jumpsquat.Value = true
		local jsquatanim = hu:LoadAnimation(jsquat.ANIM)
		jsquatanim:Play()
		wait(jsquat.Value/25)
		jsquatanim:Stop()
		-- jump
		if space == 1 then
			print("Full hop")
			local bp = Instance.new("BodyPosition", char.Torso)
			bp.position = bp.Parent.Position + Vector3.new(0,cst.jheight.Value,0)
			bp.maxForce = Vector3.new(0,math.huge,0)
			game:GetService("Debris"):AddItem(bp,.3)
		elseif space == 0 then
			print("Short hop")
			local bp = Instance.new("BodyPosition", char.Torso)
			bp.position = bp.Parent.Position + Vector3.new(0,cst.jheight.short.Value,0)
			bp.maxForce = Vector3.new(0,math.huge,0)
			game:GetService("Debris"):AddItem(bp,.3)
			end
		jumpsquat.Value = false
	end
	if key:byte() == 32 then
		script.KEYS.space.Value = true
		space = 1
	end
end

function onKeyUp(key)
	if key == "w" then
		script.KEYS.w.Value = false
	end
	if key:byte() == 32 then
		script.KEYS.space.Value = false
		space = 0
	end
end

	function onChanged6()
		game.Players.LocalPlayer.Character.Humanoid.Jump = false
	end
	game.Players.LocalPlayer.Character.Humanoid.Changed:connect(onChanged6)

function onChanged()
	if running.Value == true and script.KEYS.w.Value == false and grounded.Value == true and climbing.Value == false then
		running.Value = false
		pl.Character.Humanoid.WalkSpeed = walkspeed.Value
	end
end
function onChanged2()
	if running.Value == true --[[and script.KEYS.w.Value == false]] and grounded.Value == true and climbing.Value == false then
		running.Value = false
		pl.Character.Humanoid.WalkSpeed = walkspeed.Value
	end
end
function onChanged3()
	if running.Value == true and climbing.Value == true then
		running.Value = false
		pl.Character.Humanoid.WalkSpeed = walkspeed.Value
	end
end

mouse.KeyUp:connect(onKeyUp)
mouse.KeyDown:connect(onKeyDown)

3 comments

0

No code? Well....Why are you using a BoolValue and not something like a RemoteFunction/Event?

0

You must supply the code.

0

I have added the code. Also, I do not know what a RemoteFunction/Event is but I'll read up on it.