No one on the Roblox forum has answered this and I can't continue working on my place until it's figured out.
For some odd reason the studio doesn't read two of my variables, which have identical values, as equal. What happens is a player clicks on a brick, and a simple addition problem appears in their player gui. They can type in the answer on the gui and check the answer with a button.
function onClicked(p)
script.Parent.Number1.Value = math.random(1,5)
script.Parent.Number2.Value = math.random(1,5)
local var1 = script.Parent.Number1.Value
local var2 = script.Parent.Number2.Value
wait(1) --Needs to wait so other script can check for current Gui's and destroy them
Instance.new("ScreenGui",p.PlayerGui)
local g = p.PlayerGui.ScreenGui
Instance.new("Frame",g)
local f = g.Frame
f.Name = "Box"
f.Size = UDim2.new(0,300,0,50)
f.Position = UDim2.new(0.5,0,0.5,0)
Instance.new("TextLabel",g)
local n1 = g.TextLabel
n1.Name = "Number1"
n1.Size = UDim2.new(0,30,0,30)
n1.Position = UDim2.new(0.52,0,0.52,0)
n1.FontSize = "Size36"
n1.Text = var1
n1.BorderSizePixel = "0"
Instance.new("TextLabel",g)
local n2 = g.TextLabel
n2.Name = "Number2"
n2.Size = UDim2.new(0,30,0,30)
n2.Position = UDim2.new(0.52,100,0.52,0)
n2.FontSize = "Size36"
n2.Text = var2
n2.BorderSizePixel = "0"
Instance.new("TextLabel",g)
local p = g.TextLabel
p.Name = "PlusSign"
p.Size = UDim2.new(0,30,0,30)
p.Position = UDim2.new(0.52,50,0.52,0)
p.FontSize = "Size36"
p.Text = "+"
p.BorderSizePixel = "0"
Instance.new("TextLabel",g)
local e = g.TextLabel
e.Name = "EqualSign"
e.Size = UDim2.new(0,30,0,30)
e.Position = UDim2.new(0.52,150,0.52,0)
e.FontSize = "Size36"
e.Text = "="
e.BorderSizePixel = "0"
Instance.new("TextBox",g)
local a = g.TextBox
a.Name = "Answer"
a.Size = UDim2.new(0,30,0,30)
a.Position = UDim2.new(0.52,200,0.52,0)
a.FontSize = "Size36"
a.Text = "?"
a.BorderSizePixel = "0"
Instance.new("NumberValue",a)
local value = a.Value
value.Name = "InputValue"
value.Value = value.Parent.Text
Instance.new("TextButton",g)
local check = g.TextButton
check.Name = "Check"
check.Size = UDim2.new(0,300,0,25)
check.Position = UDim2.new(0.50,0,0.50,50)
Instance.new("NumberValue",g)
local needed = g.Value
needed.Name = "CorrectAnswer"
needed.Value = var1 + var2
local answer = game.Workspace.Answer:Clone()
answer.Parent = needed
print(g)
print(f)
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
The button has a script which, when clicked, checks the two numbers being added, what the answer should be, and what the answer typed is. All the prints were for finding out where my script was going wrong.
function check()
local input = script.Parent.Parent.Answer.Text --the answer typed
local inputvalue = script.Parent.Parent.Answer.InputValue.Value --IntValue
print("The input is "..input..".")
print("The value is "..inputvalue..".")
inputvalue = input --IntValue becomes the answer typed
print("The updated value is "..inputvalue..".")
local correct = script.Parent.Value --what the answer should be
print("Current inputvalue is "..inputvalue..".")
print("Answer should be "..correct..".")
if inputvalue == correct then --Here is the issue
print("Correct!")
print(""..inputvalue.." = "..correct.."")
else
print("Incorrect!")
print(""..inputvalue.." ~= "..correct.."")
end
end
script.Parent.Parent.Check.MouseButton1Click:connect(check)
For some reason, even when the print command tells me 'inputvalue' and 'correct' are identical numbers, the if function say's their false. Also, if I put:
if inputvalue == input then
as I stated earlier in the script, then the if function works fine. For some reason the script thinks the variable 'correct' isn't identical to 'inputvalue' despite the print command returning the exact number for help.

2 comments
Maybe it's because one is a string and one is a numerical value.
How so? I pulled both answers from a NumberValue. Would setting inputvalue = input cause the numerical value to turn into a string?