✓ Accepted answer
The problem here is that the character hasn't loaded yet. When you get the character, check if the character exists, and if it doesn't you need to wait for CharacterAdded.
local player = game.Players.LocalPlayer
local char = player.Char or player.CharacterAdded:Wait()
local runanim = char:WaitForChild("Humanoid"):LoadAnimation(script.Running)
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
char.Humanoid.WalkSpeed = 20
runanim.Looped = true
runanim:Play()
end
end)
uis.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
char.Humanoid.WalkSpeed = 16
runanim.Looped = false
runanim:Stop()
end
end)
Not related to your question, but you should also make sure that when the shift key is held to make a capital letter in the chat, it doesn't trigger the running animation.
local player = game.Players.LocalPlayer
local char = player.Char or player.CharacterAdded:Wait()
local runanim = char:WaitForChild("Humanoid"):LoadAnimation(script.Running)
uis.InputBegan:Connect(function(key, gp)
if key.KeyCode == Enum.KeyCode.LeftShift and not gp then
char.Humanoid.WalkSpeed = 20
runanim.Looped = true
runanim:Play()
end
end)
uis.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
char.Humanoid.WalkSpeed = 16
runanim.Looped = false
runanim:Stop()
end
end)