There is a few things to note here.
First, the player added function is mainly used on server scripts to capture the local player and do something when they join. Local scripts already do this as they run for each person as soon as they join the game. Also, you should use this to capture the players before using the player added function:
local Players = game:GetService("Players")
After capturing it, you can use player added like this:
Players.PlayerAdded:Connect(function(player)
end)
The player added function is already given the local player as an argument. So there is no need to write out game.Players.LocalPlayer. Also, you should only need to use WaitForChild on the root parent, not its children.
Players.PlayerAdded:Connect(function(player)
local purchases = player:WaitForChild("leaderstats").Purchases2
end)
Okay, let's move past the player added function and show you the working local script. This is if you want it to start up immmediately:
Client Script
local button = script.Parent
local players = game:GetService("Players")
local purchases = players.LocalPlayer:WaitForChild("leaderstats").Purchases2
if purchases.Value == 3 then
print("MVP")
button.Visible = true
button.Parent:WaitForChild("MVP1").TextLabel.Visible = false
else
print("Bye")
button.Visible = false
end
Server Script
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local purchases2 = Instance.new("IntValue")
purchases2.Name = "Purchases2"
purchases2.Parent = leaderstats
end)
Note:
I don't really like using UpValues, but I put it up there for simplicity sake. In order for the leaderboard to popup in the game, it must be called "leaderstats" exactly.
2 comments
That didn't work
Hmm, make sure the local script is in starter gui. Other than that, I don't know what you could've done wrong as it was tested before I posted it.