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

Why does this script not print the answer of my value which contains an "equation"?

Why does this script not print the answer of my value which contains an "equation"?

The value is a String Value , yes a String Value. Because it has to contain either " + " " - " "/ " or " * "

The String Value is currently set to "10 + 10" for test purposes.

When I click the calculate button, it should print** "20"** , right? Well... that's what it doesn't do. It prints "10 + 10" ... Why?

What can I do to make it print the answer of whatever is inside the "equation" ?

My coding is as follows:

local MainHolder = script.Parent:WaitForChild("MainHolder")
local Answer     = MainHolder:WaitForChild("Equals"):WaitForChild("Answer")
local Buttons    = MainHolder:WaitForChild("Buttons")
local Calculate  = Buttons:WaitForChild("Calculate")
local Plus       = Buttons:WaitForChild("Plus")                                     --//All of these will be used later in my script
local Minus      = Buttons:WaitForChild("Minus")
local Divide     = Buttons:WaitForChild("Divide")
local Multiply   = Buttons:WaitForChild("Multiply")
local Clear      = Buttons:WaitForChild("Clear")

Calculate.MouseButton1Click:connect(function()
	local Equation = MainHolder:WaitForChild("EquationToCalculate").Value --//Make sure the equation is actually the updated equation
	--//The equation is currently set to "10+10" for test purposes
	print(Equation) --//This just prints "10+10" instead of "20" , which should be the answer
end)

Any help is greatly appreciated!

1 answer

The reason it prints "10 + 10" is because you call it to print a string value. "10 + 10" is not the same as 10 + 10. Theres more evolved in a calculator then putting a string together. The easiest way to get around is to call it via the loadstring function. warning: Loadstring is very dangerous as it allows hackers to use anything they want. It shouldn't be used live, but if this is only for testing purposes, there's no problem.

print(loadstring("10 + 10"))

but you'll have to enable loadstring first. (It's a property in ServerScriptService.)

Loadstring on the wiki.

2 comments

0

Don't use loadstring.

0

As i said, and i quote: "It shouldn't be used live, but if this is only for testing purposes, there's no problem."

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