Random math question

Hi devs! I made a 2 scripts for random math question and its not working so i check if there is error, but there is no error did i write wrong?

text script

while true do
	wait(1)
	local number1 = tostring(script.Parent.Parent.Parent.Number1.Value)
	local number2 = tostring(script.Parent.Parent.Parent.Number2.Value)
	local sign = tostring(script.Parent.Parent.Parent.Sign.Value)
	repeat wait(1) until number1 ~= 0 and number2 ~= 0 and sign ~= 0
	if sign == 0 then
		script.Parent.Text = "Error"
	elseif sign == 1 then
	script.Parent.Text = number1.." + ".. number2.." = ?"
	elseif sign == 2 then
		script.Parent.Text = number1.." - ".. number2.." = ?"
	elseif sign == 3 then
		script.Parent.Text = number1.." * ".. number2.." = ? "
	end
	end

answer value script

local number1 = tostring(script.Parent.Parent.Number1.Value)
local number2 = tostring(script.Parent.Parent.Number2.Value)
local sign = tostring(script.Parent.Parent.Sign.Value)
repeat wait(2) until number1 ~= 0 and number2 ~= 0 and sign ~= 0
if sign == 1 then
	script.Parent.Value = number1 + number2 
elseif sign == 2 then
	script.Parent.Value = number1 - number2 
elseif sign == 3 then
	script.Parent.Value = number1 * number2 
end
1 Like

The error is likely happening where your if statements are. The variable sign is a string as you’ve used tostring when defining it, and when you equate a string to a number, it’ll always return false, so it skips over the if statements.

print("0" == 0) -- false
print(0 == 0) -- true

To fix this, remove the tostring when defining sign:

local sign = script.Parent.Parent.Parent.Sign.Value

Hopefully this works :+1:

1 Like

wow thats working! tysm for helping me

Mark his post as a solution

Summary

This text will be hidden

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.