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

Minus the current value from a GUI?

local minus = "2" -- 2
local Label = script.Parent.Parent.Parent.Height -- "Height" TextLabel
local current = print(Label.Text) -- Height text is 100 so "100"
local current2 = Label.Text -- The label text
local now = current - minus -- 100 - 2 = 98
script.Parent.MouseButton1Click:Connect(function() -- Textbutton click function
current2 = now -- The label's text is 98 now
end) -- end

This is a local script inside a text button. I have checked everything it has been named correctly. It must be my code.

So , when you click the text button , it gets the TextLabel called "Height" 's Text or value which is "100" cause I typed "100". Then minus by two and equals to 98 afterwards end itself. I am not sure why it is not working , help would be appreciated. Thanks in advance!

1 answer

✓ Accepted answer

Text like "100" and "2" are strings, and you can't perform arithmetic on strings. They must be converted to numbers first.

local label = script.Parent.Parent.Parent.Height

script.Parent.MouseButton1Click:Connect(function()
	local new_value = tonumber(label.Text) - 2 -- convert label.Text to a number and subtract 2
	label.Text = tostring(new_value) -- convert back to a string to update the label
end)

You'll notice I've also omitted a lot of the unnecessary code in your program, just for the sake of making it more concise and readable.

2 comments

0

hi, it's tostring and tonumber.

0

Mixing up my languages - think I used Python syntax. Thanks for catching that

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