Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why are my leaderboard remote functions not working?

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

1 answer

✓ Accepted answer

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

3 comments

0

my output says: ServerScriptService.Script:1: attempt to index nil with 'WaitForChild'

0

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.

0

i got it working but i needed to remove the waitforchild

This discussion is preserved as it was. New answers, comments, and votes are closed.