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

How come player is a nil value when I have it identified?

Asked by
Yeevivor4 155
9 years ago

Hi, so this block of code is in a LocalScript, and the LocalScript is in a TextButton. The TextButton is in a Frame called Frame1 , which is in another Frame called Frame2. Frame2 then is in a ScreenGui. What I'm trying to do here is that when you click a button, the Player who clicked it, will have his wood subtracted from an IntValue named "Wood".
Also, the "Wood" is an IntValue inside slots, and slots is inside another IntValue named playerstats.

The problem is that it keeps saying ** attempt to index local 'player' (a nil value).**

    wait(1)
    if game.Players.LocalPlayer then
    local player = game.Players.LocalPlayer
    function onClick()
    Wood = player.playerstats.slots:findFirstChild("Wood")

    if Wood.Value >= 3 then
    Wood.Value = Wood.Value - 3

    script.Parent.MouseButton1Click:connect(onClick)
0
Try taking "local" off. Just keep "player", when defining player. You said this is a block of code, so I assume you didn't share the entire thing. I suggest editing it and adding in the rest if this doesn't help. dyler3 1510 — 9y
0
Is this the whole script? DigitalVeer 1473 — 9y

Answer this question