1 | script.Parent.ClickDetector.MouseClick:connect( function (playerwhi) |
2 | playerwhi = playerwhi.Name |
3 | game.Players.playerwhi.leaderstats.Money = game.Players.playerwhi.leaderstats.Money + 100 |
4 | end ) |
The problem I am having is that I don't know how to access the player when I try to do it it says 11:41:07.089 - playerwhi is not a valid member of Players Also this is not a local script
The script is trying to find the child named playerwhi in Players, to get around this, you have to tell it to find the actual variable, like so:
1 | script.Parent.ClickDetector.MouseClick:connect( function (playerwhi) |
2 | playerwhi = playerwhi.Name |
3 | game.Players:FindFirstChild(playerwhi).leaderstats.Money = game.Players:FindFirstChild(playerwhi).leaderstats.Money + 100 |
4 | end ) |
From the Roblox Wiki page:
Note: If you have FilteringEnabled set to 'true', this will not fire on the server and only on the client. To avoid this, connect the event on the client and use a RemoteEvent to inform the server about it being clicked.
The best way to do this is to use a local script.
ServerScript
1 | local remoteEvent = game.ReplicatedStorage.RemoteEvent |
2 |
3 | remoteEvent.OnServerInvoke:connect( function (player) |
4 | player.leaderstats.Money = player.leaderstats.Money + 100 |
5 | end ) |
LocalScript
1 | local remoteEvent = game.ReplicatedStorage.RemoteEvent |
2 |
3 | game.Workspace.Part.ClickDetector.MouseClick:connect( function () |
4 | remoteEvent:FireServer() |
5 | end ) |