This was the error in the console.
The script you gave me
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
local DOUBLE_JUMP_POWER_MULTIPLIER = 2
local Animation = Instance.new("Animation")
Animation.Name = "DoubleJAnimation"
Animation.AnimationId = "rbxassetid://7637267231"
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 animator = humanoid:FindFirstChildOfClass("Animator")
local function animate()
if animator then
local animationTrack = animator:LoadAnimation(Animation)
animationTrack: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, animate)
The error
14:50:27.299 Workspace.Luxurious_Scripter.DoubleJumpAnimation:26: attempt to index nil with 'FindFirstChildOfClass' - Client - DoubleJumpAnimation:26
14:50:27.299 Stack Begin - Studio
14:50:27.299 Script 'Workspace.Luxurious_Scripter.DoubleJumpAnimation', Line 26 - Studio - DoubleJumpAnimation:26
14:50:27.299 Stack End - Studio
oh no i didnt read it
(dis is for word limit)
u must do da âload animtionâ part inside a function
or else it will run loadanimtion on a nil humanoid
(or u need to put da function characterAdded(newCharacter) and things invole above da humanoid:LoadAnimation() part)
Youâre actually wrong, read the error output.
You should be providing an Animation Instance inside the script.
Thatâs because this variable local animator = humanoid:FindFirstChildOfClass("Animator")
was outside the function thatâs why itâs giving you an index nil error
. Try using this script, you must provide an Animation Instance with the asset id inside of it. The Animation Instance is parented to the LocalScript
.
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character
local humanoid
local animator
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local TIME_BETWEEN_JUMPS = 0.1
local DOUBLE_JUMP_POWER_MULTIPLIER = 2
local Animation = script.Animation
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 animate()
if animator then
local animationTrack = animator:LoadAnimation(Animation)
animationTrack:Play()
end
end
local function characterAdded(newCharacter)
character = newCharacter
humanoid = newCharacter:WaitForChild("Humanoid")
animator = humanoid:FindFirstChildOfClass("Animator")
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, animate)
you should load the animation on the animator not the humanoid.
The error given from the script
16:00:51.892 Stack Begin - Studio
16:00:51.892 Script 'Workspace.Luxurious_Scripter.DoubleJumpAnimation', Line 11 - Studio - DoubleJumpAnimation:11
16:00:51.892 Stack End - Studio
So many functions that you donât even need to make. nvm im just wrong, heres an edited script.
-- Must provide an `Animation Instance` inside the script with the `rbxassetid://xxxxxxx` in it.
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")
local Animation = script.Animation
local animationTrack = animator:LoadAnimation(Animation)
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local TIME_BETWEEN_JUMPS = 0.2
local DOUBLE_JUMP_POWER_MULTIPLIER = 2
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
animationTrack:Play()
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)
This part keeps getting an error.
Try to use :WaitForChild(âAnimationâ)
My script does not have an animation in it though.
So create it, and set the AnimationId
This is what I got but line 8 is an error.
-- Must provide an `Animation Instance` inside the script with the `rbxassetid://xxxxxxx` in it.
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")
local Animation = Instance.new("Animation")
local animationTrack = animator:LoadAnimation(Animation)
Animation.AnimationId = "rbxassetid://7637267231"
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local TIME_BETWEEN_JUMPS = 0.2
local DOUBLE_JUMP_POWER_MULTIPLIER = 2
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
animationTrack:Play()
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)
You need to set AnimationId before to load it, into Animator.
So do I need to put the AnimID line under the AnimationInstance line?
Yes, after create it set animation id, then load it into animator.
So like this?
local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://7637267231"
local animationTrack = animator:LoadAnimation(Animation)
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local TIME_BETWEEN_JUMPS = 0.2
local DOUBLE_JUMP_POWER_MULTIPLIER = 2
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
animationTrack:Play()
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)
Yes.
(Ignore this is just for roblox let me post it)