Part with a number that increases

Hello Devforums!
So, I want to make a part that increases the number that is on it every time it is clicked.
But, I don’t know how :frowning:
Any answers are helpful!
Thanks!

1 Like

Do you mean once a part has been clicked a value / number will increase by 1?
If yes, add a ClickDetector to the specific part and a IntValue or NumberValue.
Name the Value however you want.
Add a script into the specific part and type following:

local NumberValue = script.Parent.NameOfTheValue    --Change "NameOfTheValue" to the name of the value.
script.Parent.ClickDetector.MouseClick:Connect(function(click)
NumberValue.Value = NumberValue.Value +1
end)

Put this in a script inside of the part

local IncreaseSize = 1 -- how much you want it to increase each time

local detector = Instance.new('ClickDetector') -- So it can detect clicks on the part
detector.Parent = script.Parent

detector.Clicked:Connect(function() -- when its clicked it will fire this function

  script.Parent.Size += Vector3.new(IncreaseSize, IncreaseSize, IncreaseSize) -- Increases the size of the part

end)
1 Like

I’m sorry but I don’t think they want to increase part size, correct me if I’m wrong

1 Like

I am pretty sure you are talking about a text label going up.

local number = 1

local detector = where the click detector is
local textlabel = where the text label is
detector.Parent = script.Parent

detector.Clicked:Connect(function() 
number = number + 1
textlabel.Text = number
end)

Also, remember to search before posting and learn the basics of scripting instead of asking for help on a script that you have not started.

5 Likes

wouldn’t this work better like this

textlabel += number

mine would only add 1 every time, yours makes it equal to 2 every time

Just editted my post so it works. I was not setting the variable to +1.

either way my line is less code lmao

local gui = Instance.new("SurfaceGui")
gui.Parent = script.Parent -- script.Parent would be the part

local textlabel = Instance.new("TextLabel")
textlabel.Parent = gui
textlabel.Size = UDim2.new(1,0,1,0)

local clickdetector = Instance.new("ClickDetector")
clickdetector.Parent = script.Parent

local num = 0

textlabel.Text = num

clickdetector.MouseClick:Connect(function()
    num = num + 1
    textlabel.Text = num
end)

like I said earlier it’s much better if you just do

textlabel.Text += num

there’s literally no difference, saving a few characters does literally nothing

3 Likes

actually there is a huge difference to this

let’s say the text is 5 but num is equal to 9

suddenly the next time you click it goes from 5 to 10 instantly, this makes it so you can’t change the text at all

also my line was wrong, you can’t add a string and a number like that

textlabel.Text = tostring(tonumber(textlabel.Text) + num)

with that line of code you can change the text whenever you want and that makes it more reliable

So basically no difference at all

1 Like

didn’t I just explain how much worse the other method is…