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

Why the function name doesn't work with the script?

I've been interested in learn scripting. So, i was testing some learderstats scripts when this happened:

Script

local Detector = script.Parent:WaitForChild("ClickDetector")
   
Detector.MouseClick:Connect(function(player)
local player = player.Name
game.Players.player.leaderstats.Cash.Value = 30
end)

Output

"player is not a valid member of Players"

Can someone explain what's wrong with the script please?

3 comments

0

MouseClick already returns the player; you're getting the player's name from the player itself on line 4, then attempting to get the player from the player's service when you already got the player? https://developer.roblox.com/api-reference/event/ClickDetector/MouseClick

0

shtu up @theedethAcaster. Ok so this is ur problem, u should be doing for line 5, this: game.Players[player].leaderstats.Cash.Value = 30

0

yeah

1 answer

✓ Accepted answer

Here is where you are wrong:

game.Players.player.leaderstats.Cash.Value = 30

You created an identifier 'game.Players.player' when there is already an existing variable in your function which is the 'player'

So it should be:

player.leaderstats.Cash.Value = 30

Either way, 'game.Players.player' is incorrect unless it would be local then 'game.Players.LocalPlayer'

1 comment

0

Thanks for the help. Also sorry for the late responce.

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