Problems with Elevator System

Hi! I have an elevator system. It is basically this:

This is the server script:

--Assigning the touch event to every door part (There are multiple elevators in the game)
for _, door in pairs(InvDoors:GetChildren()) do
	
	if door:IsA("Model") then
		local PlayerList = {} --The players currently in the elevator
		local TeleportPart = door.TeleportPart --This is the part inside the elevator
		
		--detecting player touch the elevator
		door.door.Touched:Connect(function(hit)
			
			local Character = hit.Parent
			local Player = Players:GetPlayerFromCharacter(Character)
			local isWaiting = table.find(PlayerList, Player)
			if Character and not isWaiting then
				table.insert(PlayerList, Player)
				local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
				HumanoidRootPart.CFrame = TeleportPart.CFrame
				ElevatorRemote:FireClient(Player)
			end
			
		end)
	end
end

--Exit Button Remote
ElevatorRemote.OnServerEvent:Connect(function()
	--want to remove the player from the PlayerList variable
end)

This is the local script

ElevatorRemote.OnClientEvent:Connect(function()
	Btn.Visible = true
end)

Btn.Activated:Connect(function()
	ElevatorRemote:FireServer()
	Btn.Visible = false
end)

I want that when the remote event is fired, an exit button will pop up and if the player clicks it, he will exit the elevator.
The problem is that I don’t know how to get the PlayerList variable in the ElevatorRemote function in the server script as it is a local variable located in the Touched event.
Can someone help thanks!

1 Like

you can just move the character out of the teleport pad and if the player isn’t on it anymore it won’t teleport him

1 Like

what you mean moving the player out of the teleport pad

1 Like

why u need do this? use local instead

I’d use ModuleScripts to get Tables into other scripts,

Another way would be using Ponchokings’ Gate System.

just move the player out of the elevator

The for loop you are running only teleports the player when they touch a door.

So, you don’t need to remove anyone from the PlayerList, is refreshes itself each time it runs.

Just teleport the player off the elevator when they click the button, then add back the isWaiting tag if needed.

sorry for the late reply, do you mean turning the PlayerList variable into a module script and store the player name into the module script? Thanks!

Sorry I don’t quite understand what you mean by it refreshes itself each time it runs. Can you explain further thanks

Yeah, create a module script and create a function with the PlayerList and then store the player name into it. This is what i used for my Saving Point.