Help with adding stats to player list

I tried to make my own player list and currently I am stuck on the stats of the player.

Local script
repeat
	wait()
	player = game.Players:WaitForChild(script.Parent.Parent.Name)
until player ~= nil

wait(0.25)

stat = player.leaderstats.Cash -- I think this is where my error is
script.Parent.Text = stat.Value

while true do
	wait()
	game.ReplicatedStorage.PlayerCashInvoke:InvokeServer(stat, script.Parent)
end

And I have a new script in ServerStorage for when the RemoteFunction in invoked:

New Script
game.ReplicatedStorage.PlayerCashInvoke.OnServerInvoke = function(stat, label)
	stat:GetPropertyChangedSignal("Value"):Connect(function()
		label.Text = stat.Value
	end)
end

Sooo… The part where I am getting errors is Line 8 in my local script. The output shows this:
21:31:01 -- leaderstats is not a valid member of Player Stack Begin Script 'Players.IAmPinleon.PlayerGui.Players.Frame.slots.IAmPinleon.Stat1.LocalScript', Line 8 Stack End

Thank you!

1 Like

Problem is simple: A Player can NOT access ServerScriptService or ServerStorage.
If you want the Player to be able to access PlayerMoney, then you either need to always have a copy in ReplicatedStorage which reflects the current value from the one in ServerStorage, or you move the entire thing directly into ReplicatedStorage and not do any reflecting at all.

2 Likes

Indeed. The Client does not have access to ServerStorage or ServerScriptService, only the Server does.

Again,

game.ServerStorage.PlayerMoney:FindFirstChild(player.Name):GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = stat.Value
end)

This would fail because the Client can’t access ServerStorage, if you really want to store it in ServerStorage regardless, then just reflect the Folder to ReplicatedStorage so the user can see the value.

Ah, just tested your code and got the error.

22:52:39.523 - WaitFirstChild is not a valid member of Players
22:52:39.524 - Stack Begin
22:52:39.524 - Script 'Players.SimplyData.PlayerGui.Leaderstats', Line 2
22:52:39.525 - Stack End

You are trying to call WaitFirstChild, replace that with WaitForChild.

1 Like

I updated the whole post for I fixed some but new errors sprouted.

My old errors were:

  • did WaitFirstChild instead of WaitForChild
  • can’t get access to ServerStorage/ServerScriptService through a local script

My new errors are:

  • look at the above post