How would I make a textlabel change its text (in terms of numbers) when I click a button?

Let’s say I that if I were to click a button depending on how many times I clicked it, a text label will say how much I clicked it but it is shown to the player. Like when I click a button three times, the text label will say 3. Kind of like how Cookie Clicker works. Here is the script that needs work:

local e = script.Parent.Parent.WrongClick.Text
local counter = 0

script.Parent.MouseButton1Click:Connect(function() 
	counter = counter +1
	e = counter
end)

You are reading the “Text” of the textlabel once. which means it is stored as a string instead of instance. instead you should do

local e = script.Parent.Parent.WrongClick
local counter = 0

script.Parent.MouseButton1Click:Connect(function() 
	counter = counter +1
	e.Text = counter
end)

What i did is i moved the “.Text” to the 6th line instead of 1st line. This should fix your problems

1 Like

Use this code, it will work:


local e = script.Parent.Parent.WrongClick.Text
local counter = 0

script.Parent.MouseButton1Click:Connect(function() 
	counter += 1
	e = tostring(counter)
end)

1 Like

That code wont work since you are still only changing a string instead of the textlabel instance like OP did

1 Like

Ah, I see what you mean. Your code should work for OP.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.