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!