alaaeiou
(alaaeiou)
March 17, 2021, 5:11am
#1
I’m trying to get the leaderstats of a player when they click a button but it errors.
button.MouseButton1Click:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats") -- error line
local cash = leaderstats:WaitForChild("Cash")
cash.Value += 1
end)
Error:
Attempt to index nil with ‘WaitForChild’
(It’s a server script)
Can anyone help?
Coderius
(Coderius)
March 17, 2021, 5:14am
#2
I believe it’s because you can’t use MouseButton1Click on a server-sided script.
Also I don’t think MouseButton1Click takes any parameters, so you’d have to declare the player variable outside of it.
2 Likes
If you wanted to fix this issue, fire a remote event on the client when the button is pressed, and on the server, when the remote event is fired, change the player’s leaderstats.
1 Like