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
It looks like you may not be assigning Parent correctly. As far as I know it is case sensitive and you are attempting to assign parent with a lowercase p. docs This would need to be revised in lines 4 and 9 of the leaderstats script.
It also appears that line 6 of the leaderstats script would need to be revised to local cash = Instance.new("NumberValue")
as the = operator was omitted.
The 'v' in Value in line 8 would also need to be capitalized.
The 'v's in all 'value' calls in the gravity script would also need to be capitalized.
Also it may be a good idea in the server event to use :WaitForChild() to verify that leaderstats is there.
local leaderstats = player:WaitForChild("leaderstats")
Edits for things I forgot and clarification