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)