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

Someone Only Worsened my Problem in moving variables Help please?

Asked by 8 years ago

So earlier I asked this question:

Ok so, I have this script that makes a leader board:

1game.Players.PlayerAdded:connect(function(plr)
2    local stats = Instance.new("IntValue", plr)
3    stats.Name = "leaderstats"
4    local points = Instance.new("IntValue",stats)
5    points.Name = "Copper"
6    points.Value = 0
7end)

I then want to make a button that when you click it you get 1 copper: here it is:

1function onClicked(playerWhoClicked)
2    script.Parent.BrickColor = BrickColor.DarkGray()
3    wait(6)
4    points.Value = +1
5    script.Parent.BrickColor = BrickColor.new("Reddish brown")
6end
7 
8script.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.

1function onClicked(playerWhoClicked)
2    script.Parent.BrickColor = BrickColor.DarkGray()
3    wait(5)
4    local points = playerWhoClicked.leaderstats.points
5    points.Value = points.Value+1
6    script.Parent.BrickColor = BrickColor.new("Reddish brown")
7end
8 
9script.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.

2 answers

Log in to vote
0
Answered by 8 years ago

At the end of line 4, change "points" to "Copper" and it should work now, since I don't see any other errors.

0
The thing is that the NAME is "Copper". SO when searching for it, it's Copper, not "points" as points was just a local variable in your leader board script iamnoamesa 674 — 8y
Ad
Log in to vote
2
Answered by 8 years ago

Its quite easy

because points is not a member of IntValue.

Copper is.

01function onClicked(playerWhoClicked)
02 
03    script.Parent.BrickColor = BrickColor.DarkGray()
04 
05    wait(5)
06 
07    local Copper = playerWhoClicked.leaderstats.Copper
08 
09    Copper.Value = Copper.Value+1
10 
11    script.Parent.BrickColor = BrickColor.new("Reddish brown")
12 
13end
14 
15 
16 
17script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
Yes, yes. How stupid of me. User#11440 120 — 8y

Answer this question