Hello, i’m trying to animate double jumping for a character, and it only plays for the client, and i need help to fix this. Also, if i have to play it on a server script, how do i go about getting the local player?
the script:
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = script.Parent:WaitForChild("Humanoid")
local dbjump
local Animation = Instance.new("Animation", player.Character)
Animation.AnimationId = "rbxassetid://6979528677"
dbjump = humanoid:LoadAnimation(Animation)
local HasDoubleJumped = false
local LastJump = tick()
local function jumpRequest()
if (tick()- LastJump) >= .2 then
if humanoid:GetState()== Enum.HumanoidStateType.Freefall and not HasDoubleJumped then
HasDoubleJumped = true
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
dbjump:Play()
end
end
end
humanoid.StateChanged:Connect(function(old,new)
if new == Enum.HumanoidStateType.Landed then
HasDoubleJumped = false
elseif new == Enum.HumanoidStateType.Jumping then
LastJump = tick()
end
end)
UserInputService.JumpRequest:Connect(jumpRequest)
The issue might be that you are using the humanoid to load the animation. On the server, this is usually fine, but on a local script you have to be careful.
When you call :LoadAnimation() on a humanoid, it will check to see if it has an Animator object as a child. If it doesn’t, it will create one for itself. This is key because the server is supposed to be the one that creates the animator, at least if you want it to replicate to the server.
So, my solution would just to wait for the animator to be created by the server and use that to load the animation instead.
Here’s a modified version of your script that waits for the Animator object and loads the animation from there:
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local dbjump
local Animation = Instance.new("Animation", player.Character)
Animation.AnimationId = "rbxassetid://6979528677"
dbjump = animator:LoadAnimation(Animation)
local HasDoubleJumped = false
local LastJump = tick()
local function jumpRequest()
if (tick()- LastJump) >= .2 then
if humanoid:GetState()== Enum.HumanoidStateType.Freefall and not HasDoubleJumped then
HasDoubleJumped = true
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
dbjump:Play()
end
end
end
Hope this helps! Let me know if this doesn’t work.