Someone Only Worsened my Problem in moving variables Help please?
So earlier I asked this question:
Ok so, I have this script that makes a leader board:
1 | game.Players.PlayerAdded:connect( function (plr) |
2 | local stats = Instance.new( "IntValue" , plr) |
3 | stats.Name = "leaderstats" |
4 | local points = Instance.new( "IntValue" ,stats) |
I then want to make a button that when you click it you get 1 copper: here it is:
1 | function onClicked(playerWhoClicked) |
2 | script.Parent.BrickColor = BrickColor.DarkGray() |
5 | script.Parent.BrickColor = BrickColor.new( "Reddish brown" ) |
8 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
Upon starting it gave me the error of: ServerScriptService.Script:2: attempt to index global 'points' (a nil value) I think this is because the variable from my fist scrip is a local and not a global therefore I cannot transfer it, all this caused the block to be un-clickable upon removing the local from that scrip it has no visible change, the button was still un-clickable Please help!
P.s if you find any other errors in my coding please notify me!
A person then responded with this:
You get the playerWhoClicked, now find the value inside them and change it.
1 | function onClicked(playerWhoClicked) |
2 | script.Parent.BrickColor = BrickColor.DarkGray() |
4 | local points = playerWhoClicked.leaderstats.points |
5 | points.Value = points.Value+ 1 |
6 | script.Parent.BrickColor = BrickColor.new( "Reddish brown" ) |
9 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
this only worsened my problem, now whenever I try to get my ore it gives me the error: "points is not a valid member of IntValue" every 5 seconds, I am simply asking someone to try and solve it because noone usually looks on already respended to pages.