Hello everyone, so I was following along with this YouTube video to find out how to make a double jump with an animation. I believe I copied it verbatim but somehow it still breaks. I’ve used a local script within StarterPlayerScripts. Can someone help me out, thanks.
local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://4637160832"
local FlipAnim = humanoid:LoadAnimation(Animation)
local HasDoubleJumped = false
local LastJump = tick()
local function jumpRequest
if tick() - LastJump >= .2 then
if humanoid:GetService() == Enum.HumanoidStateType.Freefall and not HasDoubleJumped then
HasDoubleJumped = true
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
FlipAnim:Play()
end
end
end
humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
HasDoubleJumped = false
end
if new == Enum.HumanoidStateType.Jumping then
LastJump = tick()
end
end)
I suggest making an instance of the Animation, put it inside ReplicatedStorage. Changing local Animation’s value to the path of this already created animation. (This is so that you don’t have to remake an instance for every client.
Alright so, what you’re doing is the following:
On every client you create an instance called “Animation”, note instances are things you can add to your game, objects, e.g. a Part.
Because every player uses this animation, you can add an Animation object to ReplicatedStorage, then instead of writing:
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://4637160832"
You’d just have to write:
local Animation = game:GetService("ReplicatedStorage").Animation -- This is a path
-- Note, please change "Animation" to whatever the name is of the Animation Object.
I just did some research and the :LoadAnimation() is deprecated.
(press the image to get redirected to the site)
Which means, it doesn’t work anymore. I didn’t know this yet prior, I will do some research for you to find how you could make this work.
Edit:
Instead of using :LoadAnimation() on the Humanoid instance you should do it on Humanoid.Animator
So your script would be:
local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local Animation = Instance.new("Animation") -- Change this to a path if you got the Animation object in game.
Animation.AnimationId = "rbxassetid://4637160832"
local FlipAnim = humanoid.Animator:LoadAnimation(Animation)
local HasDoubleJumped = false
local LastJump = tick()
local function jumpRequest
if tick() - LastJump >= .2 then
if humanoid:GetService() == Enum.HumanoidStateType.Freefall and not HasDoubleJumped then
HasDoubleJumped = true
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
FlipAnim:Play()
end
end
end
humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
HasDoubleJumped = false
end
if new == Enum.HumanoidStateType.Jumping then
LastJump = tick()
end
end)