script.Parent.ClickDetector.MouseClick:connect(function(playerwhi) playerwhi = playerwhi.Name game.Players.playerwhi.leaderstats.Money = game.Players.playerwhi.leaderstats.Money + 100 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:
script.Parent.ClickDetector.MouseClick:connect(function(playerwhi) playerwhi = playerwhi.Name game.Players:FindFirstChild(playerwhi).leaderstats.Money = game.Players:FindFirstChild(playerwhi).leaderstats.Money + 100 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
local remoteEvent = game.ReplicatedStorage.RemoteEvent remoteEvent.OnServerInvoke:connect(function(player) player.leaderstats.Money = player.leaderstats.Money + 100 end)
LocalScript
local remoteEvent = game.ReplicatedStorage.RemoteEvent game.Workspace.Part.ClickDetector.MouseClick:connect(function() remoteEvent:FireServer() end)