I’m trying to make a basic movement animation script with running and walking, but I swear every time I try to do this it always ends up with the weirdest jank.
Randomly a player will just slide across the floor with an A-Pose, and that just ruins the whole thing.
I tried using LocalScripts
at first, I tried Scripts
with RemoteEvents
, and it only got worse and worse.
I have no idea how to fix this issue and I’m going to break into hysterical screaming.
-- LOCAL SCRIPT IN STARTERCHARACTERSCRIPTS
local UIS = game:GetService("UserInputService")
local chr = script.Parent
local hrp = chr:WaitForChild("HumanoidRootPart")
local hum = chr:WaitForChild("Humanoid")
local animr = hum:WaitForChild("Animator")
local walkspeed = 12
local runspeed = 24
task.wait()
local walk = animr:LoadAnimation(script:WaitForChild("Run"))
local run = animr:LoadAnimation(script:WaitForChild("Run"))
walk.Looped = true
run.Looped = true
walk:Play(0,0,.5)
run:Play(0,0,1)
local sprinting = true
hum.WalkSpeed = runspeed
UIS.InputBegan:Connect(function(k,p)
if k.KeyCode == Enum.KeyCode.LeftShift or k.KeyCode == Enum.KeyCode.LeftControl then
sprinting = false
hum.WalkSpeed = walkspeed
end
end)
UIS.InputEnded:Connect(function(k,p)
if k.KeyCode == Enum.KeyCode.LeftShift or k.KeyCode == Enum.KeyCode.LeftControl then
sprinting = true
hum.WalkSpeed = runspeed
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
if hrp.AssemblyLinearVelocity.Magnitude > 0.5 then -- checks for movement on RootPart rather than Humanoid
if hum.FloorMaterial ~= Enum.Material.Air then -- Airborne Test
if hum.WalkSpeed > walkspeed then -- I probably should've used the Magnitude of HRP.X and HRP.Z to check this.
walk:AdjustWeight(0)
run:AdjustWeight(1)
if hrp:FindFirstChild("Running") then
hrp:FindFirstChild("Running").Volume = .5
end
else
walk:AdjustWeight(1)
run:AdjustWeight(0)
if hrp:FindFirstChild("Running") then
hrp:FindFirstChild("Running").Volume = 0
end
end
else
walk:Play(0,0,.5)
run:Play(0,0,1)
end
else
walk:Play(0,0,.5)
run:Play(0,0,1)
end
end)
Before people ask, the animations are published in my account, the game is solely owned by me, and no, I cannot disguise as Saxton.