Best way to loop the round?

Currently, I have a round system set to a function, I have a loop that checks if a variable is true, but wouldn’t this rapid call the function causing the game to eventually lag?
What should I do?

Server sided btw

game.Players.PlayerAdded:Connect(function(player)
	if table.find(Permitted, player.UserId) then
		player.Chatted:Connect(function(msg)
			if msg == "!EyeEvent" then

				if game.Workspace.HappyHome then
					LaserPart.Parent = workspace
					MinigameActive = true
				else
					Map:Clone().Parent = workspace
					LaserPart.Parent = workspace
					MinigameActive = true
				end
			elseif msg == "!EndEvent" then
				MinigameActive = false
				wait(2)
				LaserPart.Parent = game.ReplicatedStorage
			elseif msg == "!Reset" then
				workspace.HappyHome:Destroy()
				Map:Clone().Parent = workspace
			end
		end)
	end
end)


MinigameActive = false

local target_previous = Vector3.new()

function startGame(Target)
	local origin = rayOriginPart.CFrame.Position
	local rayTarget = target_previous:Lerp(Target.Position, laser_TrackingAccuracy)
	local direction = (rayTarget - origin)
	local results = workspace:Raycast(origin, direction * 100, raycastParameters)
	if not results then
		results = {Position = rayTarget}
	else
		print(results.Instance)
	end
	local distance = (results.Position - origin).Magnitude
	local LaserPosition = laserPart.Position
	LaserPart.Size = Vector3.new(laser_Thickness,laser_Thickness,distance)
	laserPart.CFrame = CFrame.new(origin, results.Position) * CFrame.new(0,0, -distance/2)

	target_previous = rayTarget
end

while true do
	if MinigameActive == true then
		Runservice.Stepped:Connect(function(dt)
			local target = FindNearest(rayOriginPart.Position)
			if target then
				startGame(target.HumanoidRootPart)
			end
		end)
	end
	wait(10)
end

If you want to fix your infinite loops you should check this topic

Hmm I don’t know if that would work well in my case, I can give it a shot tho.

Doing that it glitches my ray back.

wouldn’t this rapid call the function causing the game to eventually lag?

I don’t think that infinite loop with 10 second delay would cause greater lag than already a fixed loop.

But have you tried using this?

Hmm. not sure if that would work in this case, because if the bool doesn’t change it won’t loop

Personally, I’d only use if statements if I have around 2 - 3 conditions to check. otherwise, i’d just use tables:

local cmds = {
    ["!EyeEvent"] = function()
        -- do stuffs
        print("hi")
    end),

    ["!EndEvent"] = function()
        -- do stuffs
        print("bye!")
    end)
}

-- later on in the code
player.Chatted:Connect(function(msg)
    if cmds[msg] then
        cmds[msg]() -- basically calling the function using the key
    end
end

variable naming seems good tho.

Honestly, I would just do a custom loop within a Function.

function StartRound()
    ---- Your Code here
   ---- Wait For Round to Finish
   StartRound()
end
StartRound()

That way once the round is complete, it’ll just run the Function again to start another round and it’ll just repeat forever unless your script breaks before the function is called lol

Just simplify things and make your code more efficient to read.