Hello! I was trying to add this double jumping script of the Roblox Wiki to a map of my game. When I tested it in Roblox Studio it worked fine. I had a script in the map that when the map spawns clones a copy of the double jumping script into the Starter Character Scripts. During the round I could double jump and shortly before the end the Script destroyed the Double Jump Script.
But when I wanted to test it in the normal Roblox Client it didn't work. I know it has to do something with remote event or the place where i put the script. It is not a local script - How can I get it to work in Roblox Client as well as in Studio?
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character
local humanoid
local canDoubleJump = false
local hasDoubleJumped = false
local oldPowerlocal TIME_BETWEEN_JUMPS = 0.2 local DOUBLE_JUMP_POWER_MULTIPLIER = 1.5
function onJumpRequest()
if not character or not humanoid or not character:IsDescendantOf(workspace) or
humanoid:GetState() == Enum.HumanoidStateType.Dead then
return
end
if canDoubleJump and not hasDoubleJumped then
hasDoubleJumped = true
humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
local function characterAdded(newCharacter)
character = newCharacter
humanoid = newCharacter:WaitForChild("Humanoid")
hasDoubleJumped = false
canDoubleJump = false
oldPower = humanoid.JumpPower
humanoid.StateChanged:connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
canDoubleJump = false
hasDoubleJumped = false
humanoid.JumpPower = oldPower elseif new == Enum.HumanoidStateType.Freefall then
wait(TIME_BETWEEN_JUMPS) canDoubleJump = true
end
end)
end
if localPlayer.Character then
characterAdded(localPlayer.Character)
end
localPlayer.CharacterAdded:connect(characterAdded)
UserInputService.JumpRequest:connect(onJumpRequest)
Script by Roblox Wiki

1 comment
The script shown would only work in a LocalScript, as it references the local player and the user input service. To make a double jump script, make a remote event that tells the server that the client has pressed a button on their keyboard, as the User Input Service is only accessible on the client. Then the server handles the rest.