So, I've been experimenting a lot with KeyPressing as well as animation and it has been working out (in studio only). I would look for errors in the local logs in the actual game and would get "Attempt to index upvalue 'char' (a nil value)".
So here's the code:
local Player = script.Parent.Parent local mouse = Player:GetMouse() local char = Player.Character function onKeyDown(key) key = key:lower() if key == "r" then -------------------------------------------------------------------------- local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/Asset?ID=676773078" char.Humanoid.WalkSpeed = 0 local animTrack = char.Humanoid:LoadAnimation(animation) wait(0.5) animTrack:Play() --------------------------------------------------------------------------- wait(2.5) char.Humanoid.WalkSpeed = 16 end end mouse.KeyDown:connect(onKeyDown)
Now, this is in a LocalScript which apparently brings more complications like being unable to run things globally? Like, if I changed local char to just char, it doesn't tag char because it's global? I don't know, I'm not very adept at this.
You're not waiting for the character to load. You can do so using this method:
local char = plr.Character or plr.CharacterAdded:Wait()