I don't know how to fix this problem in my scripting. I just made the animation stop when you release the Shift key and for some reason it says Character is nil value??? Im so confused...
The Character part in this line is whats causing the error.
local playAnim = Character.Humanoid:LoadAnimation("Anim")
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function(key)
if key:lower() == string.char(48) then
local hum = game.Players.LocalPlayer.Character.Humanoid
if hum then
hum.WalkSpeed = 50
local Anim = Instance.new("Animation")
Anim.AnimationId = 'rbxassetid://2250415227'
local playAnim = Character.Humanoid:LoadAnimation(Anim)
playAnim:Play()
end
end
end)
mouse.KeyUp:connect(function(key)
if key:lower() == string.char(48) then
local hum = game.Players.LocalPlayer.Character.Humanoid
if hum then
hum.WalkSpeed = 20
local Anim = Instance.new("Animation")
Anim.AnimationId = 'rbxassetid://2250415227'
local playAnim = Character.Humanoid:LoadAnimation("Anim")
playAnim:Stop()
end
end
end)

1 comment
You never defined character...there's no need to anyway, just do hum:LoadAnimation(Anim).........also, you should be using UserInputService, KeyDown is very old, outdated, and depriciated, https://www.robloxdev.com/code-sample/UserInputService-InputBegan