Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED] How do I prevent the player from spamming double-jump to reach unlimited height?

I found this double-jump script online and I tested it: (LocalScript in PlayerGui)

local UserInputService = game:GetService("UserInputService")
local lastjumptick = tick()
local Jumped = 1
local hum = game.Players.LocalPlayer.Character:WaitForChild('Humanoid')
local anim = hum:LoadAnimation(script.Parent.Flip)

local Camera = workspace.CurrentCamera


local function onInputBegan(input,gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		local keyPressed = input.KeyCode
		if keyPressed == Enum.KeyCode.Space then
			if Jumped == 1 then
				Jumped = 2
			else
				if Jumped == 2 and tick() - lastjumptick <= .5 then
					anim:Play()
					local JumpBrick = Instance.new("Part",workspace)
					JumpBrick.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(0,-2,0)
					JumpBrick.Size = Vector3.new(2,.2,2)
					JumpBrick.Anchored = true
					JumpBrick.Transparency = 1
					game.Players.LocalPlayer.Character.Humanoid.JumpPower = 60
					game.Debris:AddItem(JumpBrick,.5)
					wait(.25)
					game.Players.LocalPlayer.Character.Humanoid.JumpPower = 50
				end
				wait(.5)
				Jumped = 1
			end
			lastjumptick = tick()
		end
	end
end
 
UserInputService.InputBegan:connect(onInputBegan)

UserInputService.InputBegan:Connect(function(keyCode)
	if keyCode.keyCode == Enum.KeyCode.Space then
		hum.WalkSpeed = 12
	end
end)

I know it's confusing and all, but I really need a solution, as my game is about to be released.

There is no errors in the output, and if I spam the SpaceBar, (I made my game PC only) the player would infinitely jump to unlimited height.

Please help!

1 comment

0

But, if it's only in a local script only you would be able to see yourself using double jump, everyone else wouldn't see it.

1 answer

✓ Accepted answer

Use debounce, you just make a variable like locla debounce = false When you do the double jump set debounce to true, and make it so if debounce is true you cannot double jump, wait whatever the cooldown is going to be and set debounce to false again. If debounce is false make sure they are able to double jump.

2 comments

0

local*

0

@broham896 Okay, I'll try.

This discussion is preserved as it was. New answers, comments, and votes are closed.