How can I make my elevator/teleporter system work with more than one elevator?

Right now, I have an elevator/teleporter system to take the player (or a group of players) from one place to another. It all works as intended until I duplicate the elevator, which has a server script inside of if that listens for remoteEvents from the client.

The issue I’m facing is that since each server script within each elevator is listening for remoteEvents from the client, so when the host changes the settings which would update the surfaceGui on the elevator, then all of the elevators change their surfaceGui.

Here is a part of my client script that fires an event for the elevator server script for reference:

lobbyGui.mapSelectionFrame.Buttons.nextButton.Activated:Connect(function()
		if map ~= nil then
			lobbyGuiEvent:FireServer("isReady")
			lobbyGui.UIPageLayout:Next()
			
			local difficulty = tonumber(difficultyText.Text)
			optionsEvent:FireServer("updateDifficulty", difficulty)
			
			local roomAmount = tonumber(roomAmoutText.Text)
			optionsEvent:FireServer("updateRoomAmount", roomAmount)
		else
			lobbyGui.mapSelectionFrame.Title.TextColor = BrickColor.new("Really red")
			task.wait(1)
			lobbyGui.mapSelectionFrame.Title.TextColor = BrickColor.new("White")
		end
	end)

And here’s the part of the server script that listens for that event:


local elevator = script.Parent
local surfaceGui = elevator.Entrance.SurfaceGui
local surfaceDifficulty = surfaceGui.Difficulty
local surfaceRoomAmount = surfaceGui.RoomAmount

optionsEvent.OnServerEvent:Connect(function(player, eventtype, value)
	if eventtype == "updateDifficulty" then
		difficulty = value
		surfaceDifficulty.Text = "Difficulty: " .. tostring(difficulty)
		surfaceDifficulty.Visible = true
	elseif eventtype == "updateRoomAmount" then
		roomAmount = value
		surfaceRoomAmount.Text = "Room Amount: " .. tostring(roomAmount)
		surfaceRoomAmount.Visible = true
	end
end)
2 Likes

Simply use collectionservice, typically used for things that need to do the same thing but are in different locations of the workspace.

If you can, just use a for loop without collectionservice if you already have all the elevators in a folder or something.

2 Likes

They were all in a folder so I used a for loop to set the current elevator and then replaced all the other elevator variables with that current elevator variable. Thanks for the help!

1 Like

Yeah no problem

30char

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.