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)
Hi
Issue is you never defined Character
So to solve this it's pretty simple. Just define Character.
local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() local mouse = plr:GetMouse() mouse.KeyDown:Connect(function(key) -- avoid using :connect use :Connect if key:lower() == string.char(48) then local hum = Char.Humanoid if hum then hum.WalkSpeed = 50 local Anim = Instance.new("Animation") Anim.AnimationId = 'rbxassetid://2250415227' local playAnim = Char.Humanoid:LoadAnimation(Anim) -- problem fixed playAnim:Play() end end end) mouse.KeyUp:Connect(function(key) -- avoid :connect if key:lower() == string.char(48) then local hum = Char.Humanoid -- use char variable if hum then hum.WalkSpeed = 20 local Anim = Instance.new("Animation") Anim.AnimationId = 'rbxassetid://2250415227' local playAnim = Char.Humanoid:LoadAnimation("Anim") -- problem fixed playAnim:Stop() end end end)
Hope this helped