Help with script

I am trying to make a game where you are in spaceship and you have to escape, but there is a monster… I want to do a gui to be a visible, but first time it gets visible but when you close, it then it won’t get visible again. This is my code so far

local killerWeapon = game.ServerStorage.ClassicSword
local plrs = game.Players
local survivors = {}
local IntermissionGui = game.StarterGui.IntermissionScreen

while wait(10) do
	
	local chosen = plrs:GetChildren()[math.random(1, #plrs:GetChildren())]
	
	chosen.PlayerGui.RolePicker.Background.Role.Text = "Monster--Testing"
	chosen.PlayerGui.RolePicker.Background.Role.TextColor3 = Color3.fromRGB(255, 0, 0)
	
	chosen.PlayerGui.RolePicker.Background.Visible=true

	killerWeapon:Clone().Parent = chosen.Backpack

	for i, plr in pairs(plrs:GetChildren())do

		if plr ~= chosen then

			table.insert(survivors, plr)
			
			plr.PlayerGui.RolePicker.Background.Role.Text = "Survivor--Testing"
			plr.PlayerGui.RolePicker.Background.Role.TextColor3 = Color3.fromRGB(0, 255, 0)
			
			plr.PlayerGui.RolePicker.Background.Visible=true
		end
	end
end

There has to be another script involved, how are you closing it? I don’t see a closing function inside the code you provided.