Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

[Fixed Like 2 days ago] Keeps saying Attempt to index local (a nil value) help please?

Asked by
neoG457 315 Moderation Voter
9 years ago

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?

0
Ignore the comments unless they help you help me. My friend is a jerk sometimes. neoG457 315 — 9y
0
Is this in a Local Script? It won't work if put into a regular script. BlackJPI 2658 — 9y
0
It is, why do you think theres local script in the tags neoG457 315 — 9y

3 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

0
It is a local script. In starterpack. neoG457 315 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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.

Log in to vote
0
Answered by
neoG457 315 Moderation Voter
9 years ago

Lol turns out I didnt type the whole animation ID Surprised you guys didnt see that.

Answer this question