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

Counter staying at 1, any fix?

Asked by 4 years ago

How this script works is when the player clicks the item the counter will go up by 1 then the item will disappear 0 -> 1

Thats all working and good

Num = 0
PickUp = script.Parent

function OnClicked(plyr)
    Num = Num + 1
    plyr.PlayerGui.Counter.Number.Text = Num
    PickUp:Destroy()
end
PickUp.ClickDetector.MouseClick:Connect(OnClicked)

But! When the counter is showing 1 and the player goes to pick up another item. Instead of changing the value to 2 it stays saying 1 and always 1.

I could just pick up 10 items and the counter will always stay at 1

Any fix?

('Counter' is a ScreenGui and 'Number' is a TextLabel)

0
Where is this script located, I'm pretty sure a player's gui can't be changed from a script outside. You would have to use a remote event sheepposu 561 — 4y
0
The script is inside a part NINJA0113 0 — 4y
0
^ You don't need a remote event, if you change it from a local script then only that player will see that amount of money. cmgtotalyawesome 1418 — 4y
0
^ You don't need a remote event, if you change it from a local script then only that player will see that amount of money. cmgtotalyawesome 1418 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Well, Identified in your script you have

Num = 0

And when you click on the part, it sets Num to Num + 1 which would always be 1.

But, You set the label's text to 0 + 1, Instead of (what it was originally) + 1

This can be fixed easily.

plyr.PlayerGui.Counter.Number.Text = tostring(tonumber(plyr.PlayerGui.Counter.Number.Text) + 1)

tostring(number) converts the number to a string as tonumber(string) converts the string to a number so we can perform arithmetic.

Ad

Answer this question