How to detect if a player is on an event etc... ( need your help )

Hi devs, i really need your help . Actually i have made a script where somes event are happening every X time, but i have a problem. I want to make a system that :

First Situation

The event is launched.
the door open
No players are entered on it.
The event closes after 60 secondes
and another event is launched.

But i want this situation could be possible too :

The event is launched.
the door open
A player enter on the event.
no other event starts while one player is in the event.
A player exit the event
door close
and another event is launched.

But actually idk how to make that … Could someone can help me ? Here is my script for an event :

local EventNames = {"SousSol"}

	SousSol = function()
		local Door = game.Workspace.Evenements.SousSol
		local frameOpen = Door:WaitForChild("DoorFrameOpen")
		local frameClose = Door:WaitForChild("DoorFrameClose")
		local frame = Door:WaitForChild("DoorFrame")
		local tweenService = game:GetService("TweenService")
		local OpenSound = frame.DoorOpen
		local CloseSound = frame.DoorClose
		local SousSolValue = game.ReplicatedStorage.ValuesEvents.SousSol
		local EventCompleted = game.ReplicatedStorage.ValuesEvents.SousSolCOMPLETED
		local StopSousSol = game.ReplicatedStorage.StopSousSol
		if EventCompleted.Value == 1 then
				local dead = false
				local thread = nil

				thread = StopSousSol.OnServerEvent:Connect(function()
					dead = true

				while dead == false do
					-- Nothing here, just kill the event

			print("SousSol Start")
		frame.CanCollide = false
			Door.EventTitle.billboardGui.Enabled = true
			Door.EventTitle.EventTitle.billboardGui.Enabled = true
		frame.Knobs.Transparency = 1
		frameClose.Knobs.Transparency = 1
		frameOpen.Knobs.Transparency = 0
		game.Workspace.AllTpParts.BasementTp.TeleportPart1.CanCollide = true
		game.Workspace.AllTpParts.BasementTp.TeleportPart1.Transparency = 0
		tweenService:Create(frame,,{CFrame = frameOpen.CFrame}):Play()
			-- Need help here , to check if player is on the event or nah and if he leaved the event too..
		print("Event end sousol")
		frame.CanCollide = true
		frame.Knobs.Transparency = 0
		frameClose.Knobs.Transparency = 0
		frameOpen.Knobs.Transparency = 1
		Door.EventTitle.billboardGui.Enabled = false
			Door.EventTitle.EventTitle.billboardGui.Enabled = false
		game.Workspace.AllTpParts.BasementTp.TeleportPart1.CanCollide = false
		game.Workspace.AllTpParts.BasementTp.TeleportPart1.Transparency = 1
		tweenService:Create(frame,,{CFrame = frameClose.CFrame}):Play()

while true do
local EventName = EventNames[RandomObject:NextInteger(1, #EventNames)]
print("Event searching")
task.wait(5) --Wait 60 seconds between events when game will be published.
1 Like

when the player exit the event, just call the another event function

Yes but how? Bcs actually events are randomly chosen with this :

local EventNames = {"SousSol","AnotherEventName","AnotherEventName"} -- etc...

Sorry for late reply. You can just call an random event after exiting

--player exits event
EventNames[math.random(1, #EventNames)]()