How could i improve my teleporter system

hello guys, i’ve been working on this party teleporter system, where you can have multiple players inside of it to teleport to another place, and there is also a timer so it can wait for other players to be inside

please check this out, and help me make this better or get rid of any bugs that might be inside of this teleporter system
here is the place of the teleport system to check it out
teleport_place.rbxl (75.4 KB)

this isn’t a tutorial im just trying to explain it to people so they can at least understand what it is
i mean this isn’t a tutorial but you could follow like it is one

What you’ll need for the teleporter system

it also uses 3 other main things to help make it easier for you and myself when i was making the teleporter system

it uses the tag editor plugin/collection service, to add as many teleporters as needed and it also keeps it neater by having it all in 1 script

it also uses a safe teleport to help teleport players and also help handling failed teleports

and lastly it uses zone plus for detecting players entering or exiting the teleporter

Getting Started

alright lets get started on setting up this system

image
to begin with add the zone plus into replicated storage
image
there is a teleport script in server script service (it doesn’t really teleport its there to initialize the teleporters in the collectionservice)
image
tag list is from the tag editor plugin
safe teleport is the teleport is there to help safely teleport players
teleport module is the main script for the teleport system
and then the teleport gui to display the time and amount of players inside

there is a part called “Zone” and its basically its there to detect if any players are inside of the teleporter or not
image
image
and the part is inside of the group/model called teleporter, the name can be anything i just happened to name it that way (also its in the workspace btw)
and then the group/model has some attributes inside of it

it has attributes such as

  • MinPlayers – this is the minimum amount of players needed to start the timer
  • MaxPlayers – this is the maximum amount of players that are allowed to be inside
  • PlaceId – the place where all the players are teleported
  • Time – the amount of time that it waits until it teleports the players to the game
    image
    image
    they have to be named like this or it won’t work *case sensitive
    and the type has to be a number or it won’t work

the attributes makes it easier to change values without having to go inside the script

after you do that, then just use the tag editor plugin and tag the teleporter as “teleporter”


and finally you’re finished setting it up!

Scripts

alright for the first script its called “TeleportScript” doesn’t actually teleport just initializes the teleporters that are tagged from the tag editor plugin,
it has a for loop going through each of the teleporters and sets it up for being ready to be used

local CollectionService = game:GetService("CollectionService")
local Teleporters = CollectionService:GetTagged("teleporter")
local ServerStorage = game:GetService("ServerStorage")

local teleportModule = require(ServerStorage.TeleportModule)

for _,teleporter in pairs(Teleporters) do
	teleportModule.Clone(teleporter)
end

next im going to talk about the teleport module, im only going to talk about the main functions
comments in the code for easier understanding

these two functions will update the display of the timer and players
if you want to change how they display then you can do so

local function updateTimer()
	timeText.Text = string.format("Time: %s",teleporter:GetAttribute("Time"))
end

local function updatePlayer()
	playerText.Text = string.format("Players: %s", tostring(#partyPlayersList))
end

next function is the teleport function
this teleport function teleports all the players to the place then resets everything

local function teleport()
	SafeTeleport(placeId, partyPlayersList) --teleports the players
	table.clear(partyPlayersList) --clears the list of players inside the elevator
	teleporter:SetAttribute("Time", timerValue) --resets the time
	updateTimer() --updates timer gui
	updatePlayer() --updates player gui
end

next we got the timer function
run service heartbeat fires every 60 frames per second
it runs every frame and there is 60 frames in 1 second
it is an event function meaning it can be disconnected at any time
debounce adds 1 per 1/60 of a second or a 60th of a second
this function will keep running unless if the time is at 0 or unless there isn’t enough players inside the teleporter (min players)
the timer will update ever second
then once the timer hits 0 then it will stop the connection and then it will activate the teleport function

local function timer()
	dbounce += 1 --adds 1 to debounce 
	if dbounce % 60 ~= 0 then return end --if debounce isn't 60 then it stops the code
	teleporter:SetAttribute("Time",  teleporter:GetAttribute("Time") -1) --the timer value is subtracted by 1
	updateTimer()--updates the text for the timer
	if teleporter:GetAttribute("Time") <= 0 then timerConnect:Disconnect() teleport() return end --then if the timer value is 0 or less then it will stop and fire the teleport function
end

next we got the add player function

local function addPlayer(Player)
	local addPlayer = table.find(partyPlayersList,Player) -- finds the player inside the list
	if addPlayer then return end -- if player is already in table then it will stop the function
	if #partyPlayersList < maxPlayers then -- if the total amount of players is less than max players
		table.insert(partyPlayersList,Player) --adds player into the list
		updatePlayer() --updates the gui for the amount of players inside
		if #partyPlayersList >= minPlayers then -- if there is enough players then it'll start the timer
			if timerConnect.Connected then return end -- if the timer already has started it won't start again
			dbounce = 0 timerConnect = RunService.Heartbeat:Connect(timer) --starts the timer 
		end
	end
end

i’ll comment inside the script

local function removePlayer(Player)
	local removePlayer = table.find(partyPlayersList, Player) -- finds the player to remove
	if not removePlayer then return end -- if there isn't the player to remove then it stops the function 
	table.remove(partyPlayersList, removePlayer) --then it removes the player from the list
	updatePlayer() --it updates the players text in the gui
	if #partyPlayersList < minPlayers then --if the amount of players inside is less than the minimum players
		timerConnect:Disconnect() --then it stops the counter from counting down
		teleporter:SetAttribute("Time", timerValue) --resets the timer back to the original value
		updateTimer() --updates the text for the timer
	end
end

limitations of the teleporter system

  • teleport service cannot be used in studios
  • max players must be at least be 1 or higher to be able to start the countdown for the timer
  • the place id must be a valid place to be able to teleport players to
  • the zone part must be inside the group/model of which the tagged teleporter using the tag “teleporter”
  • changing any of the scripts used for the teleporter system which may cause errors
  • tagging anything that’s not a model/group or there isn’t a part called “Zone” and the model/group doesn’t have the correct attributes with the correct names / type
  • changing / modifying anything for the teleport system could cause it to break

thanks for reading this and hope you have a great day/night

here’s the place to test it out
teleport_place.rbxl (75.4 KB)

3 Likes