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

When clicked , minus 2 from the current number in a text label?

local minus = "2"
local current = TextLabel.Text
local now = math.abs(current) - minus
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.TextLabel.Text = now
 end
end)

This is inside a local script inside a text button. When you click the text button it minus off the current number from the text label.

Lets say the text label has 100 when you click this text button the text will minus off 2 so it will become 98.

The ending has an error not sure why. Please help! Thanks in advance :)

3 comments

0

you need to convert the text to a number before performing arithmetic on it math.abs(tonumber(TextLabel.Text)) - tonumber(minus)

0

also you have an extra end inside the function, remove it

0

Use tonumber() and if you're using numbers, you won't be needing the quotation marks. Just say local minus = 2

1 answer

You might want to look here:

local minus = "2" --You don't add strings for a number
local current = TextLabel.Text
local now = math.abs(current) - minus
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.TextLabel.Text = now
 end
end)

This would be the correct script.

local minus = 2
local current = TextLabel.Text
local now = math.abs(current) - minus
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.TextLabel.Text = now
 end
end)

I hope this works for you as I am new to scripting.

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