I have made this script with the aid of the roblox wiki and it seem that when I run the localscript from a players backpack the game Outputs Players.Player1.Backpack.LocalScript:3: attempt to index global 'Humanoid' (a nil value) 15:35:03.697 - Stack Begin 15:35:03.698 - Script 'Players.Player1.Backpack.LocalScript', Line 3 15:35:03.699 - Stack End
Could sombody point out the mistake i must be making
local animation = Instance.new("Animation") animation.AnimationId = "235600467" local animTrack = Humanoid:LoadAnimation(animation) function onKeyDown(key) key = key:lower() if key == "e" then animTrack:Play() end end script.Parent.Parent:GetMouse().KeyDown:connect(onKeyDown)
You forgot to define Humanoid. After line 2, add this:
local Humanoid = nil local player = game.Players.LocalPlayer local character = player.Character if not character or not character.Parent then character = player.CharacterAdded:wait() end Humanoid = character:WaitForChild("Humanoid")
This should be a local script if you didn't all ready know.
Wiki tutorial : http://wiki.roblox.com/index.php?title=Animations Demo tutorial : http://www.roblox.com/games/144922434/Animation-Example
local animation = Instance.new("Animation") local numId = 235600466 --235600467 animation.AnimationId = "http://www.roblox.com/asset/?id="..numId -- Main animation Id local Humanoid = nil local player = game.Players.LocalPlayer local character = player.Character local mouse = player:GetMouse() -- Gets the local players mouse (Obv) if not character or not character.Parent then -- Credit to merely here. character = player.CharacterAdded:wait() end Humanoid = character:WaitForChild("Humanoid") local animTrack = Humanoid:LoadAnimation(animation) mouse.KeyDown:connect(function(key) if key:lower() == "e" then -- Also its missing the "key" function from the keyboard. print(key) animTrack:Play() end end)