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
1 | script.Parent.MouseButton 1 Click:Connect( function (player) |
2 | game.ReplicatedStorage.PowerUps.Gravity:FireServer() |
3 | end ) |
leaderstats
01 | local function onPlayerJoin(player) |
02 | local leaderstats = Instance.new( "Folder" ) |
03 | leaderstats.Name = "leaderstats" |
04 | leaderstats.Parent = player |
05 |
06 | -- Display an 'IntValue' on leaderboard |
07 | local gold = Instance.new( "IntValue" ) |
08 | gold.Name = "Gold" |
09 | gold.Value = 0 |
10 | gold.Parent = leaderstats |
11 | end |
12 |
13 | game.Players.PlayerAdded:Connect(onPlayerJoin) |
and the gravity function
1 | game.ReplicatedStorage.PowerUps.Gravity.OnServerEvent:Connect( function (player) |
2 | if player.leaderstats.cash.value > = 10 then |
3 | player.leaderstats.cash.value = player.leaderstats.cash.value - 10 |
4 | game.Workspace.Gravity = 90 |
5 | end |
6 | 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