Not Detecting The Right Value?

so i am making a game where is a machine that gives you a math problem. it is randomly generating the numbers for the problem but for testing purposes i did that it only can generate zero. ok so the problem is that when a value in a gui is the answer to the math problem it should normally print “right” but that’s not the case! it prints “wrong” and i have no idea on how to fix this. (and the value in the gui is set.)

Script:

local firstNumber = math.random(0,0)
local lastNumber = math.random(0,0)
local Answer = (firstNumber + lastNumber)

print(Answer)

script.Parent.SurfaceGui.FirstNum.Text = firstNumber
script.Parent.SurfaceGui.LastNum.Text = lastNumber

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if plr.PlayerGui.Game.Content.NumBall.CurrentlyHolding.Value == Answer then
		print("right")
		script.Parent.ClickDetector:Destroy()
		plr.PlayerGui.Main.Cursor.Image = "http://www.roblox.com/asset/?id=9761205525"
		script.Parent.Transparency = 1
		plr.PlayerGui.Game.Content.YTP.Visible = true
		plr.PlayerGui.Game.Content.YTP.TotalNum.Text = plr.YTP.Value
		plr.PlayerGui.Game.Content.YTP.Got.Text = script.Parent.Give.Value
		plr.PlayerGui.Game.Content.YTP.Got:TweenPosition(UDim2.new(0,0,0.3,0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.3)
		wait(0.3)
		plr.YTP.Value += script.Parent.Give.Value
		plr.PlayerGui.Game.Content.YTP.Got.Position = UDim2.new(0,0,1,0)
		wait(0.5)
		plr.PlayerGui.Game.Content.YTP.Visible = false
	elseif plr.PlayerGui.Game.Content.NumBall.CurrentlyHolding.Value == "Notholding" then
		print("not holding anything")
	elseif plr.PlayerGui.Game.Content.NumBall.CurrentlyHolding.Value ~= Answer then
		print("wrong")
	end
end)

So what I suggest is adding some prints to debug,
First of what does Answer print,
Second add a print above the if statement that prints the value of the input

Answer prints well the answer which is 0

and the second print also prints 0 (when i collected the item that changes it) (i printed the value in the gui)

What is CurrentlyHolding (ex. IntValue)

I’m pretty sure the reason it’s false is because CurrentlyHolding is a StringValue, convert it 2 a number.

Check this for methods such as tonumber()

3 Likes

the CurrentlyHolding is a string value

I figured, look at my edited post, tell me if you get an error. (You might)

You can also use the tonumber() function to turn any string into a number

1 Like

woah i didn’t even think of that! thank you very much!