Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Total click counter won't add?

I've been making a total click counter and for some reason when I test the game the click counter won't work and there will be an error stating

"Players.MLG_Gamer9876.PlayerGui.GUI.counter:3: attempt to perform arithmetic on field 'Text' (a string value)"

and I have no idea what that means, but here's the script...


local text = script.Parent.totalclicks
script.Parent.click.MouseButton1Click:Connect(function()
	text.Text = "Total Clicks:"..text.Text + 1
end)


1 answer

✓ Accepted answer

You are trying to add a number to a string value. You have to convert the text to a number first to perform math operations. It should look like this:

local text = script.Parent.totalclicks
script.Parent.click.MouseButton1Click:Connect(function()
    text.Text = tostring(tonumber(text.Text) + 1)
end)

tonumber converts string to number and tostring does the opposite. (In this case tostring is not really necesarry. It's just for better understanding.)

3 comments

0

memguy the number only goes up to 1 and then doesn't add up anymore

0

oh yeah my bad

0

fixed it

This discussion is preserved as it was. New answers, comments, and votes are closed.