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

Jump on spacebar pressed, works in studio after you disable and re enable it, help?

So as I said, it will not work unless you disable and re-enable it every time, no idea why, there are no outputs at all.

This is in a LocalScript in a hopper bin.

Here's the code:

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character

local cooldown = 5
mouse = player:GetMouse()

debounce = false

mouse.KeyDown:connect(function(key)
if debounce == true then return end
debounce = true
if key:byte() == 32 then --spacebar is 32
sj = Instance.new("BodyThrust", character.Torso)
sj.force = Vector3.new(0,3000,0)
wait(0.5)
sj:Destroy()
wait(cooldown)
debounce = false
end
end)

If you can explain how you got it to work I'd appreciate it.

And if you are up for it, maybe tell me how to convert it so it's not in a tool, but like a double press spacebar to active or something like that.

Any help would be appreciated.

1 answer

Just change the value of Player.Character.Humanoid.Jump (Boolean value) to true and it will make the person jump. Don't worry about making it false again, after the character lands it should become false

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character

local cooldown = 5
mouse = player:GetMouse()

debounce = false

mouse.KeyDown:connect(function(key)
if debounce == true then return end
debounce = true
if key:byte() == 32 then --spacebar is 32
character.Humanoid.Jump = true
wait(cooldown)
debounce = false
end
end)

If you are trying to have a higher jump then try using bodyforces to be inserted to every part of the character when it spawns:

ServerScript

game.Players.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function(Character)
		for i,v in pairs(Character:GetChildren()) do
			local float = Instance.new("BodyForce", v)
			float.force = Vector3.new(0, 16, 0) --Mess around with the number until you are satisfied
		end
	end
end

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