I want to achieve a script where gui buttons become invisible after clicking on a button. That is easy, the problem is I want to make the button be an in-game currency purchase, that costs 10 Tickets.
For some reason, it can’t get the leaderstats from the player. I tried so many youtube videos and a little old forums about it… I can’t find an answer. So I come here to get one directly myself.
Yes, the value is named leaderstats, yes the leaderboard works and everything works fine.
This is the error that shows in the output. Players.SuperBirth1.PlayerGui.ColaLaunchGUI.Frame.TextButton1.Script:6: attempt to index nil with 'leaderstats’
Here is the code.
All the “locals” below Player are the gui stuff that should become invisible.
local Player = game.Players.LocalPlayer
local button1 = script.Parent
local button2 = script.Parent.Parent.TextButton2
local label = script.Parent.Parent.TextLabelwhere
script.Parent.MouseButton1Click:Connect(function()
if Player.leaderstats.Tickets.Value >= 10 then
print("oh wow you have enough money!")
Player.leaderstats.Tickets.Value = Player.leaderstats.Tickets.Value - 10
button1.Visible = false
button2.Visible = false
label.Visible = false
else
print("loser")
end
end)
The entire reason why I wasn’t using LocalScript was because I tried it earlier and it didn’t work, but now that you made me try it again; it works. I might have done something wrong when doing the local script. (initially)