I am making a game and want to make a power up shop that can affect all players and reset after a certain amount of time similar to Toh. Here are the scripts i have at the moment
inside the button
script.Parent.MouseButton1Click:Connect(function(player)
game.ReplicatedStorage.PowerUps.Gravity:FireServer()
end)
leaderstats
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Display an 'IntValue' on leaderboard
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
and the gravity function
game.ReplicatedStorage.PowerUps.Gravity.OnServerEvent:Connect(function(player)
if player.leaderstats.cash.value >= 10 then
player.leaderstats.cash.value = player.leaderstats.cash.value - 10
game.Workspace.Gravity = 90
end
end)
My output keeps saying leaderstats is not a valid member of player

3 comments
my output says: ServerScriptService.Script:1: attempt to index nil with 'WaitForChild'
Delete from line 1 and put it at line 2. It has to be in the function otherwise player hasn't been specified yet and would in fact be nil. Then, instead of player.leaderstats just use leaderstats as it will have been specified.
i got it working but i needed to remove the waitforchild