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

Help with the script please?

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

2 answers

✓ Accepted answer

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)

1 comment

0

Thanks!

##Additional Note

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)

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