Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Solved] Animation stops on client but not on server?

Asked by 4 years ago
Edited 4 years ago

This question has been solved by the original poster.

I made a sprinting script (a localscript in the PlayerGui) that makes you sprint with an animation when you double tap and hold the W key. A wierd thing is happening: when you stop holding W, your walk animation returns to normal, but only on the client side. On the server side, the sprint animation keeps going permanently

local plr = game.Players.LocalPlayer
local char = plr.Character
local UserInputService = game:GetService("UserInputService")

local WTapped = false
local Time = 0.15
local running = false

UserInputService.InputBegan:Connect(function(Input, GameStuff)
 if GameStuff then return end
 if Input.KeyCode == Enum.KeyCode.W then
  if not WTapped then
  WTapped = true
   wait(Time)
   WTapped = false
  else
    while UserInputService:IsKeyDown(Enum.KeyCode.W) do
        if running == false then
        running = true
    char.Animate.walk.WalkAnim.AnimationId = "rbxassetid://3819460931"
    char.Humanoid.WalkSpeed = 25
end
    wait()
    end
  end
 end
end)

UserInputService.InputEnded:Connect(function(Input, GameStuff)
    if GameStuff then return end
    if Input.KeyCode == Enum.KeyCode.W and running == true then
        running = false
        char.Animate.walk.WalkAnim.AnimationId = "rbxassetid://180426354"
        char.Humanoid.WalkSpeed = 16
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago

So it turns out I am not very smart... all I had to do was load the sprint animation and stop it

local plr = game.Players.LocalPlayer
local char = plr.Character
local UserInputService = game:GetService("UserInputService")

local WTapped = false
local Time = 0.15
local running = false

UserInputService.InputBegan:Connect(function(Input, GameStuff)
 if GameStuff then return end
 if Input.KeyCode == Enum.KeyCode.W then
  if not WTapped then
  WTapped = true
   wait(Time)
   WTapped = false
  else
    while UserInputService:IsKeyDown(Enum.KeyCode.W) do
        if running == false then
        running = true
    char.Animate.walk.WalkAnim.AnimationId = "rbxassetid://3819460931"
    char.Humanoid.WalkSpeed = 25
end
    wait()
    end
  end
 end
end)

UserInputService.InputEnded:Connect(function(Input, GameStuff)
    if GameStuff then return end
    if Input.KeyCode == Enum.KeyCode.W and running == true then
        running = false
        char.Humanoid:LoadAnimation(script.running):Stop() --- << here is the solution
        char.Animate.walk.WalkAnim.AnimationId = "rbxassetid://180426354"
        char.Humanoid.WalkSpeed = 16
    end
end)
0
glad u got it working royaltoe 5144 — 4y
Ad

Answer this question