I am trying to make a Baldi's Basics game, but the script in the GUI I'm using for the problems isn't working correctly. Some variables don't get set, such as BaldiMad not being set to true when I need it to be.
Here is my code:
script.Parent.Parent.Number1.Text = tostring(math.random(0, 9)) script.Parent.Parent.Number2.Text = tostring(math.random(0, 9)) local num = 1 local wrongAnswers = 0 local runservice = game:GetService("RunService") function onRenderStep() baldiMad = game.ServerStorage.BaldiMad.Value if baldiMad == true then game.Players:GetPlayers()[1].PlayerGui.Music:Stop() end textbookNum = game.ServerStorage.TextbookNum.Value amountOfText = game.ServerStorage.NumberOfTextbooks.Value end runservice:BindToRenderStep("ResetVariables", Enum.RenderPriority.Camera.Value - 1, onRenderStep) script.Parent.FocusLost:connect(function() if tonumber(script.Parent.Text) and num <= 1 then if tonumber(script.Parent.Text) == tonumber(script.Parent.Parent.Number1.Text) + tonumber(script.Parent.Parent.Number2.Text) then script.Parent.Parent.Checkmark1.Visible = true script.Parent.Parent.NotNumber.Visible = false else baldiMad = true game.ServerStorage.BaldiSpeed.Value = game.ServerStorage.BaldiSpeed.Value + 1 wrongAnswers = wrongAnswers + 1 game.Players:GetPlayers()[1].PlayerGui.Music:Stop() script.Parent.Parent.Xmark1.Visible = true script.Parent.Parent.NotNumber.Visible = false end num = num + 1 script.Parent.Parent.Number1.Text = tostring(math.random(0, 9)) script.Parent.Parent.Number2.Text = tostring(math.random(0, 9)) elseif tonumber(script.Parent.Text) and num == 2 then if tonumber(script.Parent.Text) == tonumber(script.Parent.Parent.Number1.Text) + tonumber(script.Parent.Parent.Number2.Text) then script.Parent.Parent.Checkmark2.Visible = true script.Parent.Parent.NotNumber.Visible = false else baldiMad = true wrongAnswers = wrongAnswers + 1 game.ServerStorage.BaldiSpeed.Value = game.ServerStorage.BaldiSpeed.Value + 1 game.Players:GetPlayers()[1].PlayerGui.Music:Stop() script.Parent.Parent.Xmark2.Visible = true script.Parent.Parent.NotNumber.Visible = false end num = num + 1 if amountOfText < 1 then script.Parent.Parent.Number1.Text = tostring(math.random(0, 9)) script.Parent.Parent.Number2.Text = tostring(math.random(0, 9)) else script.Parent.Parent.Number1.Text = "0" script.Parent.Parent.Number2.Text = "0" script.Parent.Parent.Plus.Visible = false script.Parent.Parent.Divide.Visible = true end elseif tonumber(script.Parent.Text) and num == 3 and game.ServerStorage.NumberOfTextbooks.Value <= 1 then if tonumber(script.Parent.Text) == tonumber(script.Parent.Parent.Number1.Text) + tonumber(script.Parent.Parent.Number2.Text) then script.Parent.Parent.Checkmark3.Visible = true script.Parent.Parent.NotNumber.Visible = false else baldiMad = true wrongAnswers = wrongAnswers + 1 game.ServerStorage.BaldiSpeed.Value = game.ServerStorage.BaldiSpeed.Value + 1 game.Players:GetPlayers()[1].PlayerGui.Music:Stop() script.Parent.Parent.Xmark3.Visible = true script.Parent.Parent.NotNumber.Visible = false end num = 1 wrongAnswers = 0 script.Parent.Parent.Number1.Text = tostring(math.random(0, 9)) script.Parent.Parent.Number2.Text = tostring(math.random(0, 9)) script.Parent.Parent.Parent.Enabled = false if baldiMad == true and textbookNum == 1 or textbookNum == 2 then game.Workspace.Baldi:SetPrimaryPartCFrame(CFrame.new(10, 6, 45)) game.Workspace.Baldi.LookScript.Disabled = true game.Workspace.Baldi.DecalPart.Anchored = false game.Workspace.Baldi.AIScript.Disabled = false elseif baldiMad == true and textbookNum > 2 then game.Workspace.Baldi.LookScript.Disabled = true game.Workspace.Baldi.DecalPart.Anchored = false game.Workspace.Baldi.AIScript.Disabled = false end script.Parent.Parent.ModalButton.Visible = false game.Workspace.Textbooks:WaitForChild("Textbook"..textbookNum):Destroy() game.ServerStorage.NumberOfTextbooks.Value = game.ServerStorage.NumberOfTextbooks.Value + 1 script.Parent.Parent.Checkmark1.Visible = false script.Parent.Parent.Xmark1.Visible = false script.Parent.Parent.Checkmark2.Visible = false script.Parent.Parent.Xmark2.Visible = false script.Parent.Parent.Checkmark3.Visible = false script.Parent.Parent.Xmark3.Visible = false script.Parent.Parent.NotNumber.Visible = false script.Disabled = true elseif tonumber(script.Parent.Text) and num == 3 and game.ServerStorage.NumberOfTextbooks.Value >= 2 then baldiMad = true wrongAnswers = wrongAnswers + 1 game.ServerStorage.BaldiSpeed.Value = game.ServerStorage.BaldiSpeed.Value + 1 game.Players:GetPlayers()[1].PlayerGui.Music:Stop() script.Parent.Parent.Xmark3.Visible = true script.Parent.Parent.NotNumber.Visible = false num = 1 wrongAnswers = 0 script.Parent.Parent.Number1.Text = tostring(math.random(0, 9)) script.Parent.Parent.Number2.Text = tostring(math.random(0, 9)) script.Parent.Parent.Plus.Visible = true script.Parent.Parent.Divide.Visible = false script.Parent.Parent.Parent.Enabled = false if baldiMad == true and textbookNum == 1 or textbookNum == 2 then game.Workspace.Baldi:SetPrimaryPartCFrame(CFrame.new(10, 6, 45)) game.Workspace.Baldi.LookScript.Disabled = true game.Workspace.Baldi.DecalPart.Anchored = false game.Workspace.Baldi.AIScript.Disabled = false elseif baldiMad == true and textbookNum > 2 then game.Workspace.Baldi.LookScript.Disabled = true game.Workspace.Baldi.DecalPart.Anchored = false game.Workspace.Baldi.AIScript.Disabled = false end script.Parent.Parent.ModalButton.Visible = false local textbookToBeDestroy = "Textbook"..textbookNum game.Workspace.Textbooks:WaitForChild(textbookToBeDestroy):Destroy() game.ServerStorage.NumberOfTextbooks.Value = game.ServerStorage.NumberOfTextbooks.Value + 1 script.Parent.Parent.Checkmark1.Visible = false script.Parent.Parent.Xmark1.Visible = false script.Parent.Parent.Checkmark2.Visible = false script.Parent.Parent.Xmark2.Visible = false script.Parent.Parent.Checkmark3.Visible = false script.Parent.Parent.Xmark3.Visible = false script.Parent.Parent.NotNumber.Visible = false script.Disabled = true elseif not tonumber(script.Parent.Text) then script.Parent.Parent.NotNumber.Visible = true end end)