Have this script here. It’s is meant to make my character actually double jump, which it doesn’t. It’s also meant to play my custom r6 jump animation then my custom r6 double jump animation. Of course the actual jump animation plays since that’s just using Roblox’s script but double jump and double jump animation isn’t playing. Here’s what I got:
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character
local humanoid
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local TIME_BETWEEN_JUMPS = 0.1 -- The time before you can do another jump
local DOUBLE_JUMP_POWER_MULTIPLIER = 1 -- The amount of times you can jump in the air
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
-- Player Jumps Here
local plrAnimator = humanoid:FindFirstChildOfClass("Animator")
if plrAnimator then
local JumpAnimation = plrAnimator:LoadAnimation()
JumpAnimation:Play()
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)
end
Start by taking out everything related to the connections of your function onJumpRequest and your function characterAdded. Put the characterAdded function out of the onJumpResquest function.
Don’t use LoadAnimation every time you want to play your animation. It is preferable to initialize JumpAnimation in the function onCharacterAdded.
Since you are using the CharacterAdded method of the Player instance, don’t place your LocalScript in StarterCharacterScripts ; instead, put it in StarterPlayerScripts . Otherwise, a new script will be created each time the player obtains a new character, which is unnecessary.
Don’t forget to pass the Animation instance to the LoadAnimation method of the Animator.
After adjustment your script should look like this:
local UserInputService = game:GetService("UserInputService")
local localPlayer = game:GetService("Players").LocalPlayer -- Dont forgot to use GetService
local oldPower
local humanoid
local character
local JumpAnimation -- Put it out of the onJumpRequest function
local canDoubleJump = false
local hasDoubleJumped = false
local TIME_BETWEEN_JUMPS = 0.1 -- The time before you can do another jump
local DOUBLE_JUMP_POWER_MULTIPLIER = 1 -- The amount of times you can jump in the air
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
if JumpAnimation then
JumpAnimation:Play()
end
humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
local function characterAdded(newCharacter) -- Put it out of the onJumpRequest function
character = newCharacter
humanoid = newCharacter:WaitForChild("Humanoid")
hasDoubleJumped = false
canDoubleJump = false
oldPower = humanoid.JumpPower
-- Load The Animation Here When New Character Is Added
local plrAnimator = humanoid:FindFirstChildOfClass("Animator")
JumpAnimation = plrAnimator:LoadAnimation()
JumpAnimation.Priority = Enum.AnimationPriority.Action
JumpAnimation:Play()
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 -- Put it out of the onJumpRequest function
characterAdded(localPlayer.Character)
end
localPlayer.CharacterAdded:Connect(characterAdded) -- Connect need uppercase to the first letter
UserInputService.JumpRequest:Connect(onJumpRequest) -- Connect need uppercase to the first letter