Game crashes whenever my autoroll and quickroll r both on

Hello my roblox studio freezes due to “Script timeout: exhausted allowed execution time” whenever my autoroll and quickroll r both on and exceed the pityCount of 10. im dead lost and dk what to do plss help

here is my script:

local rollEvent = game:GetService("ReplicatedStorage").Remotes:WaitForChild("RollEvent")
local pityEvent = game:GetService("ReplicatedStorage").Remotes:WaitForChild("pityEvent")
local quickRollEvent = game:GetService("ReplicatedStorage").Remotes:WaitForChild("QuickRollEvent")
local quickRollPityEvent = game:GetService("ReplicatedStorage").Remotes:WaitForChild("QuickRollPityEvent")
local pityUpdateEvent = game:GetService("ReplicatedStorage").Remotes:WaitForChild("pityUpdate")

local rollDisplay = script.Parent.Parent.RollingFrame
local rollButton = script.Parent

local guiParent = script.Parent.Parent.Parent
local rollGui = guiParent.RollGui

local autoRollButton = rollGui.AutoRollButton
local autoRoll = false

local quickRollButton = rollGui.QuickRollButton
local quickRoll = false

local debounce = false
local count = 0
local originalVisibility = {}

local amountOfRolls = game:GetService("Players").LocalPlayer:FindFirstChild("leaderstats").Rolls

pityUpdateEvent.OnClientEvent:Connect(function(pityCount, pityThreshold)
	if pityCount == 0 then
		count = 0
	end
end)

local function rollButtonEvent()
	if not debounce then

		rollDisplay.Visible = true
		rollButton.Visible = false
		rollButton.Active = false
		rollButton.Interactable = false
		
		autoRollButton.Visible = false
		autoRollButton.Active = false
		autoRollButton.Interactable = false
		
		quickRollButton.Visible = false
		quickRollButton.Active = false
		quickRollButton.Interactable = false

		count = count + 1

		if count > 10 then
			print("pity system active")

			count = 0

			pityEvent:FireServer()
			debounce = true

			task.wait(3.5)

			rollDisplay.Visible = false
			rollButton.Visible = true
			rollButton.Active = false
			rollButton.Interactable = false
			
			quickRollButton.Visible = true
			
			autoRollButton.Visible = true
			
			amountOfRolls.Value = amountOfRolls.Value +1

			quickRollButton.Active = true
			quickRollButton.Interactable = true

			task.wait(1)
			
			rollButton.Active = true
			rollButton.Interactable = true

			rollButton.Active = true
			rollButton.Interactable = true
			

			debounce = false
		else
			rollEvent:FireServer()
			debounce = true

			task.wait(3.5)

			rollDisplay.Visible = false
			rollButton.Visible = true
			rollButton.Active = false
			rollButton.Interactable = false
			
			quickRollButton.Visible = true
			
			autoRollButton.Visible = true
			
			amountOfRolls.Value = amountOfRolls.Value +1

			quickRollButton.Active = true
			quickRollButton.Interactable = true

			task.wait(1)
			

			rollButton.Active = true
			rollButton.Interactable = true
			
			rollButton.Active = true
			rollButton.Interactable = true

			debounce = false
		end
	end
end

local function quickRollRollEvent()
	if not debounce then
		rollDisplay.Visible = true
		rollButton.Visible = false
		rollButton.Active = false
		rollButton.Interactable = false

		autoRollButton.Visible = false
		autoRollButton.Active = false
		autoRollButton.Interactable = false
		
		quickRollButton.Visible = false
		quickRollButton.Active = false
		quickRollButton.Interactable = false

		count = count + 1

		if count > 10 then
			print("pity system active")

			count = 0

			quickRollPityEvent:FireServer()
			
			debounce = true

			task.wait(1.5)

			rollDisplay.Visible = false
			rollButton.Visible = true
			rollButton.Active = false
			rollButton.Interactable = false

			autoRollButton.Visible = true
			
			quickRollButton.Visible = true

			amountOfRolls.Value = amountOfRolls.Value + 1 
		
			autoRollButton.Active = true
			autoRollButton.Interactable = true
		
			task.wait(1)
			autoRollButton.Active = true
			autoRollButton.Interactable = true

			quickRollButton.Active = true
			quickRollButton.Interactable = true

			task.wait(1)

			rollButton.Active = true
			rollButton.Interactable = true

		else
			quickRollEvent:FireServer()

			task.wait(1.5)

			rollDisplay.Visible = false
			rollButton.Visible = true
			rollButton.Active = false
			rollButton.Interactable = false

			autoRollButton.Visible = true
			
			quickRollButton.Visible = true

			amountOfRolls.Value = amountOfRolls.Value +1
			
			autoRollButton.Active = true
			autoRollButton.Interactable = true
		
			task.wait(1)
			autoRollButton.Active = true
			autoRollButton.Interactable = true
			
			quickRollButton.Active = true
			quickRollButton.Interactable = true

			task.wait(1)

			rollButton.Active = true
			rollButton.Interactable = true
			
			debounce = false
		end
	end
end

quickRollButton.MouseButton1Up:Connect(function()
		if quickRoll == false then
			quickRoll = true

			quickRollButton.TextColor3 = Color3.fromRGB(0, 249, 0)

		else
	
			quickRoll = false
			quickRollButton.TextColor3 = Color3.fromRGB(255, 38, 0)

		end
	end)

autoRollButton.MouseButton1Up:Connect(function()
		
		if autoRoll == false then
			autoRoll = true
			
			autoRollButton.TextColor3 = Color3.fromRGB(0, 249, 0)
			if quickRoll == false then
				repeat
					rollButtonEvent()
				until quickRoll == true or autoRoll == false
				
			end

			if quickRoll == true then
				repeat
					quickRollRollEvent()
				until quickRoll == false or autoRoll == false
			end

		else
			autoRoll = false
			autoRollButton.TextColor3 = Color3.fromRGB(255, 38, 0)

			rollButton.Interactable = true
			rollButton.Active = true
		end
end)
	

script.Parent.MouseButton1Up:Connect(function()
	if quickRoll == false then
		rollButtonEvent()
	else
		quickRollRollEvent()
	end
end)

Your repeat loops are missing a task.wait().

repeat
    task.wait() -- Add this for your quickRollRollEvent() loop as well.
    rollButtonEvent()
until quickRoll == true or autoRoll == false

You MUST have some sort of task.wait() in a repeat or while loop to prevent this error. Otherwise your loop will fire constantly, which crashes your game.

Hope this helps.

thanks cutie

jidsojgierjigerhoinh3ihg3

1 Like