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

How does on go about doing an mathematical operation on a string value?

I'm trying to get this script to put a decal on a screen, from a gui textbox, but the output tells me that i cannot do math on a string value. Any help is most appreciated

button = script.Parent
DecalId = script.Parent.DecalId
screen1 = game.Workspace.screen1.Decal.Texture
screen2 = game.Workspace.screen2.Decal.Texture

function onclicked()
	screen1 = "http://www.roblox.com/asset/?id="..button.idInput.Text - 1
	screen2 = "http://www.roblox.com/asset/?id="..button.idInput.Text - 1
end

script.Parent.idInput.MouseButton1Down:connect(onclicked)

2 answers

You have to convert a string to a number to do math on it, use tonumber() :

ExampleString = "300"
print(tonumber(ExampleString) - 100) --Would print 200

So in your case:

screen1 = "http://www.roblox.com/asset/?id="..(tonumber(button.idInput.Text) - 1)
screen2 = "http://www.roblox.com/asset/?id="..(tonumber(button.idInput.Text) - 1)

You're concatenating it before you're subtracting one. Put the number in parenthesis with the math. Lua automatically converts numerical strings into numbers when you do math on them.

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