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 8 years ago
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

Log in to vote
0
Answered by 8 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:

script.Parent.ClickDetector.MouseClick:connect(function(playerwhi)
    playerwhi = playerwhi.Name
    game.Players:FindFirstChild(playerwhi).leaderstats.Money = game.Players:FindFirstChild(playerwhi).leaderstats.Money + 100
end)
0
Thanks! CybeTech 37 — 8y
Ad
Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 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

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)

Answer this question