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)
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.