Animated Double Jump Script Doesn't Work

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)
1 Like
  1. Are you the owner of the game?
  2. Are you the owner of the animation as well?
  3. 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.

The animation works fine everywhere else and yes I own the game and animation.

Also I’m not too sure what this means, this is my first YT follow along with scripting seeing as I’m more of a builder/modeler/ui Dev.

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.
1 Like

I just did some research and the :LoadAnimation() is deprecated.
image
(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)
2 Likes

Isn’t tick deprecated? I would’ve thought you’d use os.time instead

Tick is not deprecated, however it’s exploitable on the client so os.time is preffered.

1 Like

You didn’t add () to the end of this