I have been Trying to add a custom running animation to my Roblox character. I used a local script to replace the default walking animation ID with my running animation. It works perfectly in the client side but In the server side it does not stop the animation. I have tried many different solutions and read a lot of developer forum post but nothing worked for me.
Developer forum post I read
video having the bug recorded
local UserInputservice = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local SprintSpeed = 30
local NormalSpeed = 16
local NormalCameraFOV = 70
local SprintCameraFOV = 90
local camera = workspace.CurrentCamera
local tweenService = game:GetService("TweenService")
local lastWPressed = tick()
local DELTA_W_THRESHOLD = 0.2
UserInputservice.InputBegan:Connect(function(Input, gameProcessed)
local timeSinceLetGoOfW = tick() - lastWPressed
if Input.KeyCode == Enum.KeyCode.W and timeSinceLetGoOfW <= DELTA_W_THRESHOLD then
--game.ReplicatedStorage.Events.RemoteEvents.Running:FireServer("Run")
Player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://13923972310" --Running Animation
Player.Character.Humanoid.WalkSpeed = SprintSpeed
tweenService:Create(camera, TweenInfo.new(0.5), {FieldOfView = SprintCameraFOV}):Play()
end
end)
UserInputservice.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
--game.ReplicatedStorage.Events.RemoteEvents.Running:FireServer("Walk")
--Player.Character.Animate.walk.WalkAnim:Stop()
lastWPressed = tick()
Player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://13897363668" --Walking Animation
Player.Character.Humanoid.WalkSpeed = NormalSpeed
tweenService:Create(camera, TweenInfo.new(0.5), {FieldOfView = NormalCameraFOV}):Play()
end
end)
I would appreciate if anyone could try to help me. Thank you!
1 Like
First of all:
*Animations on the clients replicate on the server
If while saving the animation on roblox you turned the Looped boolean true you shouldnt have any problem, so you shouldnt use the remote event to start the animation on the server because it plays twice or thats at least what i believe that causes the problem but could you show the remote events scripts please?.
Thank you Very much for replying.
I Used a remote event to try to get it to work but it still did not work so I removed the remote event.
But Anyways this is the Remote event script that I used (I commented it in the game since it too failed to work.)
P.S: When publishing the Run animation I did turn on looped and set animation priority to Action.
local Remote = game:GetService("ReplicatedStorage").Events.RemoteEvents.Running
local RunAnimation = Instance.new("Animation")
RunAnimation.AnimationId = "rbxassetid://13923972310"
Remote.OnServerEvent:Connect(function(Player, Animation)
local Animator = Player.Character.Humanoid:WaitForChild("Animator")
local RunAnimationTrack = Animator:LoadAnimation(RunAnimation)
if Animation == "Run" then
RunAnimationTrack:Play()
else
RunAnimationTrack:Play()
RunAnimationTrack:Stop()
end
end)
Thank you.
Ok so i may have found the problem:
local Remote = game:GetService("ReplicatedStorage").Events.RemoteEvents.Running
local RunAnimation = Instance.new("Animation")
RunAnimation.AnimationId = "rbxassetid://13923972310"
Remote.OnServerEvent:Connect(function(Player, Animation)
local Animator = Player.Character.Humanoid:WaitForChild("Animator")
local RunAnimationTrack = Animator:LoadAnimation(RunAnimation) --
if Animation == "Run" then
RunAnimationTrack:Play()
else
RunAnimationTrack:Play()
RunAnimationTrack:Stop()
end
end)
Ok so we should move these to the local script instead, the problem was that you were loading another animation in after the RemoteEvent fires again changing the LoadedAnim to another complete diferent animation leaving the other running anim playing and you couldnt stop it because you were stopping the current walking animation instead of the other dunno if u understood me
local UserInputservice = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local chr = Player.Character or Player.CharacterAdded:Wait()
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://13923972310"
local LoadedAnimation
local SprintSpeed = 30
local NormalSpeed = 16
local NormalCameraFOV = 70
local SprintCameraFOV = 90
local camera = workspace.CurrentCamera
local tweenService = game:GetService("TweenService")
local lastWPressed = tick()
local DELTA_W_THRESHOLD = 0.2
UserInputservice.InputBegan:Connect(function(Input, gameProcessed)
local timeSinceLetGoOfW = tick() - lastWPressed
if Input.KeyCode == Enum.KeyCode.W and timeSinceLetGoOfW <= DELTA_W_THRESHOLD then
Animation.AnimationId = "rbxassetid://13923972310"
if LoadedAnimation ~= nil then
LoadedAnimation:Stop()
end
LoadedAnimation = chr:WaitForChild("Humanoid"):WaitForChild("Controller"):LoadAnimation(Animation)
LoadedAnimation:Play()
Player.Character.Humanoid.WalkSpeed = SprintSpeed
tweenService:Create(camera, TweenInfo.new(0.5), {FieldOfView = SprintCameraFOV}):Play()
end
end)
UserInputservice.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
--game.ReplicatedStorage.Events.RemoteEvents.Running:FireServer("Walk")
--Player.Character.Animate.walk.WalkAnim:Stop()
lastWPressed = tick()
Animation.AnimationId = "rbxassetid://13897363668" --Walking Animation
if LoadedAnimation ~= nil then
LoadedAnimation:Stop()
end
LoadedAnimation = chr:WaitForChild("Humanoid"):WaitForChild("Controller"):LoadAnimation(Animation)
LoadedAnimation:Play() Player.Character.Humanoid.WalkSpeed = NormalSpeed
tweenService:Create(camera, TweenInfo.new(0.5), {FieldOfView = NormalCameraFOV}):Play()
end
end)
Let me know if this works! (Sorry for the many edits its pretty late here where i leave and im not thinking well lol)
I am Very sorry to be troubling you. But when I run your script The output gives a infinite yield.
Once again Thank you for taking your time to reply and I am sorry to trouble you
P.S: “Real_GameingGod” Here is my developer account.
Oh im sorry i spelled it wrong change the Controller to Animator
It still contains the same bug as before
Could you show me the client? like how the animations sees?
Maybe you could try this… i have no idea why this happens:
local UserInputservice = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local chr = Player.Character or Player.CharacterAdded:Wait()
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://13923972310"
Animation.Parent = chr:WaitForChild("Humanoid"):WaitForChild("Animator")
local LoadedAnimation
local SprintSpeed = 30
local NormalSpeed = 16
local NormalCameraFOV = 70
local SprintCameraFOV = 90
local camera = workspace.CurrentCamera
local tweenService = game:GetService("TweenService")
local lastWPressed = tick()
local DELTA_W_THRESHOLD = 0.2
UserInputservice.InputBegan:Connect(function(Input, gameProcessed)
local timeSinceLetGoOfW = tick() - lastWPressed
if Input.KeyCode == Enum.KeyCode.W and timeSinceLetGoOfW <= DELTA_W_THRESHOLD then
Animation.AnimationId = "rbxassetid://13923972310"
if LoadedAnimation ~= nil then
print("Should have stopped")
LoadedAnimation:Stop()
end
LoadedAnimation = chr:WaitForChild("Humanoid"):WaitForChild("Controller"):LoadAnimation(Animation)
LoadedAnimation:Play()
Player.Character.Humanoid.WalkSpeed = SprintSpeed
tweenService:Create(camera, TweenInfo.new(0.5), {FieldOfView = SprintCameraFOV}):Play()
end
end)
UserInputservice.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
--game.ReplicatedStorage.Events.RemoteEvents.Running:FireServer("Walk")
--Player.Character.Animate.walk.WalkAnim:Stop()
lastWPressed = tick()
Animation.AnimationId = "rbxassetid://13897363668" --Walking Animation
if LoadedAnimation ~= nil then
print("Stopped running")
LoadedAnimation:Stop()
end
LoadedAnimation = chr:WaitForChild("Humanoid"):WaitForChild("Controller"):LoadAnimation(Animation)
LoadedAnimation:Play() Player.Character.Humanoid.WalkSpeed = NormalSpeed
tweenService:Create(camera, TweenInfo.new(0.5), {FieldOfView = NormalCameraFOV}):Play()
end
end)
This is the client end.
It works perfectly in client.
Ohh wait wait its because of this line at input ended
LoadedAnimation:Play()
Change it to
LoadedAnimation:Stop()
Or if that doesnt work try changing it to
for i,v in ipairs(chr:WaitForChild("Humanoid"):WaitForChild("Animator"):GetPlayingAnimationTracks()) do
v:Stop()
end
If that doesnt fix the problem maybe the problem lays within your script that plays the walk and idle anims