13:47:26.241 - local po = game.Players.LocalPlayer; --Get the player loca:2: attempt to index local 'po' (a nil value) 13:47:26.242 - Stack Begin 13:47:26.242 - Script 'local po = game.Players.LocalPlayer; --Get the player loca', Line 2 13:47:26.243 - Stack End
local po = game.Players.LocalPlayer; --Get the player local Mouse = po:GetMouse(); --Get the mouse Mouse.KeyDown:connect(function(Key) --Activated the KeyDown function with GetMouse if (Key:lower() == "k") then --Pick key to use local po = game.Players.LocalPlayer local Power = Instance.new("Animation")---name before the "=" neoNob Power.AnimationId = "220836646"--Same here neoN0b local animTrack = po.Character.Humanoid:LoadAnimation(Power)--name in parentases, neoN0b animTrack:Play()--Play pls end end)
How do I fix this?
First, tab your code correctly. That has solved the last two problems I've read, you should get in the habit.
local po = game.Players.LocalPlayer; --Get the player local Mouse = po:GetMouse(); --Get the mouse Mouse.KeyDown:connect(function(Key) --Activated the KeyDown function with GetMouse if (Key:lower() == "k") then -- Pick key to use local po = game.Players.LocalPlayer local Power = Instance.new("Animation") -- name before the "=" neoNob Power.AnimationId = "220836646"--Same here neoN0b local animTrack = po.Character.Humanoid:LoadAnimation(Power) -- name in parentases, neoN0b animTrack:Play()--Play pls end end)
Now the error is telling you that po
is a nil
value. That means it's not a thing.
po = game.Players.LocalPlayer
so po
is supposed to be the LocalPlayer. But there isn't a LocalPlayer.
That probably means this is a Script object instead of a LocalScript. Script objects can't use LocalPlayer.
First off, GetMouse is depricated. Don't use it anymore. You have to use UserInputService or ContextActionService. I prefer UserInputService.
local UIService = game:GetService("UserInputService") UIService.InputBegan:connect(function(input) if input.KeyCode = Enum.KeyCode.K then local po = game.Players.LocalPlayer local Power = Instance.new("Animation") Power.AnimationId = "220836646" local animTrack = po.Character.Humanoid:LoadAnimation(Power) animTrack:Play() end end)
UserInputService uses InputObjects. These can give you all the information based on mouse position, keycode, and other things. View the API of UserInputService here and InputObjects here.
Lol turns out I didnt type the whole animation ID Surprised you guys didnt see that.