Hello guys! This is my first time messing with scripts and i found this script in a youtube video. I made it step by step but I don’t know what went wrong!! When i keep pressing spacebar i just fly up to space!!
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character
local humanoid
local Animation = Instance.new("Animation")
Animation.AnimationId = "http://www.roblox.com/asset/?id=4662771858"
local ConseguePular = true
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local TIME_BETWEEN_JUMPS = 0.2
local DOUBLE_JUMP_POWER_MULTIPLIER = 2.5
local JumpAmount = script.Parent.DoubleJump.Jumps.Value -- How much jumps player has
local JumpRest = JumpAmount
local Faltando = script.Parent.DoubleJump.JumpRest
Faltando.Value = JumpAmount
local Debounce = false
local BodyForce = Instance.new("BodyForce")
BodyForce.Name = "BFeffect"
BodyForce.Force = Vector3.new(0,1500,0)
BodyForce.Parent = nil
local BodyVelocity = Instance.new("BodyPosition")
BodyVelocity.Name = "BVeffect"
BodyVelocity.Parent = nil
BodyVelocity.P = 2500
BodyVelocity.D = 250
BodyVelocity.MaxForce = Vector3.new(5000,0,5000)
function onJumpRequest()
if ConseguePular == true and Debounce == false then
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
local Track = humanoid:LoadAnimation(Animation)
Track:Play()
StickManJumpAnimation.StickManJump:Play()
wait()
humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
Faltando.Value = JumpRest
if JumpRest <= 0 then
canDoubleJump = false
hasDoubleJumped = true
ConseguePular = false
wait(5) -- Regen Jump
for v = 0,JumpAmount do
JumpRest = v
Faltando.Value = v
wait(.2)
end
ConseguePular = true
end
Debounce = true
local keysPressed = UserInputService:GetKeysPressed()
for _,key in pairs(keysPressed) do
if key.KeyCode == Enum.KeyCode.W then
character.HumanoidRootPart.Velocity = character.HumanoidRootPart.CFrame.lookVector * 150
elseif key.KeyCode == Enum.KeyCode.S then
character.HumanoidRootPart.Velocity = character.HumanoidRootPart.CFrame.lookVector * 150
elseif key.KeyCode == Enum.KeyCode.A then
character.HumanoidRootPart.Velocity = character.HumanoidRootPart.CFrame.lookVector * 150
elseif key.KeyCode == Enum.KeyCode.D then
character.HumanoidRootPart.Velocity = character.HumanoidRootPart.CFrame.lookVector * 150
end
end
wait(.2)
Debounce = false
end
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
JumpRest = JumpRest + 1
canDoubleJump = false
hasDoubleJumped = false
humanoid.JumpPower = oldPower
if JumpRest <= 0 then
BodyForce.Parent = nil
end
elseif new == Enum.HumanoidStateType.Freefall then
BodyForce.Parent = character.HumanoidRootPart
JumpRest = JumpRest - 1
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)
You can put this script in StarterPlayerCharacter inside of LocalScript
Create 2 NumberValue or IntValue
Rename 1 for Jumps - How many jumps does the player have
Rename 2 for JumpRest - How much jumps remaining - Set to 0
Not following their code to a T, because it pointlessly goes to the parent and then right back down into the script (script.Parent.DoubleJump.Jumps when it can just be script.Jumps).
Using WaitForChild instead, as you may be running into either a replication timing scenario or something with a conflicting name being indexed instead of the script.
You ought to do code review rather than copy and paste raw what people give you and post when something goes wrong, without any evident tweaking from your end.
local jumps = 1 -- number of double jumps (0=single jump,1=double jump,2=triple jump etc)
local jumped = 0
game:GetService("UserInputService").JumpRequest:connect(function()
if jumped < jumps + 1 and jumped > 0 then
game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Velocity =
Vector3.new(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Velocity.X,
game:GetService("Players").LocalPlayer.Character.Humanoid.JumpPower,
game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Velocity.Z) -- simulates a jump
end
jumped = jumped + 1 -- counts number of jumps
end)
game:GetService("Players").LocalPlayer.Character.Humanoid:GetPropertyChangedSignal("FloorMaterial"):connect(function()
jumped = 0 -- resets jump count when landed on the ground
end)
(Put this script in game > StarterPlayer > StarterCharacterScripts)
Edit 1: Removed debounce as it had no purpose.