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

[SOLVED] Make the player only jump once, even if the spacebar is held down?

I want to (the question), I searched all over for something like this, just found how to make a double jump script, completely contrasting my question.

Here's my script

local UserInputService = game:GetService("UserInputService")

local LshiftKey = Enum.KeyCode.LeftShift
local SpaceKey = Enum.KeyCode.Space

local function IsShiftKeyDown()
	return UserInputService:IsKeyDown(LshiftKey)
end

local function SpaceKeyDown()
	return UserInputService:IsKeyDown(SpaceKey)
end

local function KeyPressed(input)
	if IsShiftKeyDown() then
		script.Parent.Humanoid.WalkSpeed = 32
	else
		script.Parent.Humanoid.WalkSpeed = 16
	end
	if SpaceKeyDown() then
		wait(0.005)
		script.Parent.Humanoid.WalkSpeed = 32
		wait(0.2)
		script.Parent.Humanoid.WalkSpeed = 16
	end
end

UserInputService.InputBegan:Connect(KeyPressed)
UserInputService.InputEnded:Connect(KeyPressed)

At lines 20 to 25, it fires first time when the player jumps (with the spacebar held), then after > 1 jumps, it fires randomly.

( Important Note: This script is very basic as my scripting knowledge isn't that high (which is probably a problem considering the question). I'll try to understand if I get any complex answers and probably ask dumb questions regarding it. Really hope I was as constructive as possible to my current question. )

1 comment

0

The script is a 'Local Script' inside 'game/StarterPlayer/StarterCharacterScripts'

2 answers

✓ Accepted answer

Local script in StarterGui:

db = true
game:GetService("UserInputService").InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.Space then
        if db == true then
            plr = game.Players.LocalPlayer
            char = plr.Character
            char.Humanoid.JumpPower = 0
            db = false
            wait(5)
            db = true
            char.Humanoid.JumpPower = 50
        end 
    end
end)

That script should make the player only be able to jump every five seconds.

If this helped please up vote and accept this answer.

All the best,

PrismaticFruits

3 comments

0

If I reply late, I am doing some changes to my liking to see if it works.

0

The script makes me stop when I hold the space bar, then after 5 secs, allows me to jump like bunny hopping

0

This helped me frame my script, if it is allowed, I will post my answer and mark your answer as the correct

BIG THANKS to PrismaticFruits for the sample script, which helped me frame my answer

I implemented some parts of Prismatic's Sample script, and it worked! Here's the final answer.

local db = 0
local UserInputService = game:GetService("UserInputService")

local LshiftKey = Enum.KeyCode.LeftShift
local SpaceKey = Enum.KeyCode.Space

local function IsShiftKeyDown()
	return UserInputService:IsKeyDown(LshiftKey)
end

local function SpaceKeyDown()
	return UserInputService:IsKeyDown(SpaceKey)
end

local function KeyPressed(input, gameProcessedEvent)
	if IsShiftKeyDown() then
		script.Parent.Humanoid.WalkSpeed = 32
	else
		script.Parent.Humanoid.WalkSpeed = 16
	end
	if SpaceKeyDown() then
		if db == 0 then
		wait(0.005)
		script.Parent.Humanoid.WalkSpeed = 32
		wait(0.2)
		script.Parent.Humanoid.WalkSpeed = 16
		script.Parent.Humanoid.JumpPower = 0
		db = 1
		UserInputService.InputEnded:Wait()
		if not SpaceKeyDown() then
		db = 0
		script.Parent.Humanoid.JumpPower = 50	
		end
		end
	end
end

local function changejump(input)
	if not SpaceKeyDown() then
		db = 0
		script.Parent.Humanoid.JumpPower = 50
	end
end

UserInputService.InputBegan:Connect(KeyPressed)
UserInputService.InputEnded:Connect(KeyPressed)
UserInputService.InputEnded:Connect(changejump)

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