Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with the script please?

Asked by 9 years ago
1script.Parent.ClickDetector.MouseClick:connect(function(playerwhi)
2    playerwhi = playerwhi.Name
3    game.Players.playerwhi.leaderstats.Money = game.Players.playerwhi.leaderstats.Money + 100
4end)

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

Log in to vote
0
Answered by 9 years ago

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:

1script.Parent.ClickDetector.MouseClick:connect(function(playerwhi)
2    playerwhi = playerwhi.Name
3    game.Players:FindFirstChild(playerwhi).leaderstats.Money = game.Players:FindFirstChild(playerwhi).leaderstats.Money + 100
4end)
0
Thanks! CybeTech 37 — 9y
Ad
Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

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

1local remoteEvent = game.ReplicatedStorage.RemoteEvent
2 
3remoteEvent.OnServerInvoke:connect(function(player)
4    player.leaderstats.Money = player.leaderstats.Money + 100
5end)

LocalScript

1local remoteEvent = game.ReplicatedStorage.RemoteEvent
2 
3game.Workspace.Part.ClickDetector.MouseClick:connect(function()
4    remoteEvent:FireServer()
5end)

Answer this question