Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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!

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. broham896 54 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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.

0
local* broham896 54 — 4y
0
@broham896 Okay, I'll try. Sensei_Developer 298 — 4y
Ad

Answer this question