Something is wrong with my script and I don't understand what is it

So I am trying to make a multiplication game for my sister because she forgot multiplication and I am running into a problem that when the answer is incorrect the gui pops up that show that the answer is “correct” so here is my script for the remotes:

local RS = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:Connect(function(plr)
  --creates check values
	local fld = Instance.new("Folder",plr)
	fld.Name = "tFs"
	
	local aLd = Instance.new("BoolValue",fld)
	aLd.Name = "ReadyToGo"
	
end)

--When the remote is executed it checks the values if it matches to the multiplication

RS.Check.OnServerEvent:Connect(function(plr, pA, aA, aTs)
	local totalAm = pA * aA
	local matgui = plr:WaitForChild("PlayerGui"):WaitForChild("MathGui")
	local closetime = 5
	local ch = plr:WaitForChild("tFs"):WaitForChild("ReadyToGo")
	
  --looks in if the total amount of that was in textlabels matches the textbox text
	if not totalAm == aTs then
		matgui.Frame.NTA.Visible = true
		matgui.Frame.NTA.Ats.Text = matgui.Frame.NTA.Ats.Text.." "..aTs
         --Closes the frame that pops up (when answere incorrectly)
		repeat
			matgui.Frame.NTA.Laikmatis.Text = "Šitas langelis užsidarys už: "..closetime
			closetime -= 1
			wait(1)	
		until closetime == 0
		if closetime == 0 then
			matgui.Frame.NTA.Visible = false
			ch.Value = true
		end
	else
		matgui.Frame.TA.Visible = true
          --Closes the frame that pops up (when answered correctly)
		repeat
			matgui.Frame.TA.Laikmatis.Text = "Šitas langelis užsidarys už: "..closetime
			closetime -= 1
			wait(1)	
		until closetime == 0
		if closetime == 0 then
			matgui.Frame.TA.Visible = false
			ch.Value = true
		end
	end 
end)
 -- Update text labels and set ch.Value to false so  the function from the localscript would be able to execute again
RS.Update.OnServerEvent:Connect(function(plr, pS, aS)
	local matgui = plr:WaitForChild("PlayerGui"):WaitForChild("MathGui")
	local ch = plr:WaitForChild("tFs"):WaitForChild("ReadyToGo")
	matgui.Frame.PirmasSkaicius.Text = pS
	matgui.Frame.AntrasSkaicius.Text = aS
	ch.Value = false
end)

and here is the localscript:

local RS = game:GetService("ReplicatedStorage")
local PS = script.Parent.PirmasSkaicius
local AS = script.Parent.AntrasSkaicius
local PSG = math.random(1, 10)
local ASG = math.random(1, 10)
local totAm
local but = script.Parent.TextButton
local plr = game:GetService("Players").LocalPlayer

but.MouseButton1Click:Connect(function()
	
	totAm = script.Parent.Ats.Text
	local psa = tonumber(PS.Text)
	local asa = tonumber(AS.Text)
	local another = PSG * ASG
	local matgui = script.Parent.Parent.Parent.MathGui
	local closetime = 5
	local ch = plr:WaitForChild("tFs"):WaitForChild("ReadyToGo")
	RS.Check:FireServer(PSG, ASG, totAm)
	
 --Simple check on it when the value is set true it changes the amounts
	while ch.Value == false do
		wait()
		if ch.Value == true then
			PSG = math.random(1,10)
			ASG = math.random(1,10)
			RS.Update:FireServer(PSG, ASG)
		end
	end
	
	
end)
1 Like

I suggest adding comments in your code so others understand what’s going on. Because you worked on this script only you know what it does without reverse engineering it.
Edit here’s a comment

--a comment in Lua

You may need to run a tostring() function to convert an integer to a string.

In other words, you’re comparing an integer (number) to a string (words).

As I don’t really understand what this is, it’s difficult for me, but it’s possible this is the solution.

(replace this with the first line of the RS.Check function

local totalAm = tostring(pA * aA)

It is still the same even when I changed the thing.

What if you try printing out the values you recieve with remote event?

it returns the values that it gets from FireServer, looks everything good tho but the frame popup doesn’t look good

Oh! I think I found the issue!

When comparing values, you can’t do:

if not totalAm == aTs then

But rather:

if totalAm ~= aTs then