I am currently working on a Hub where people can stand in teleporters like people use in Tower Defense games, That you have to wait for a little and eventually you get teleported to a different server.
But my question was with the script i will post below, Is that. Will the plrs name be inserted in the correct Table? Or will it be mixed up, since i don’t want to teleport the wrong players to another game mode for example.
Module Script:
local module = {}
local HungerGames = workspace.Hub.MiniGames.HungerGames.Portals
module.TeleportPlaces = {
["MiniGames"] = {
["HungerGames"] = {
portal1 = {
name = HungerGames.portal1.Name;
teleportTo = workspace.SpawnLocation.CFrame;
playerTable = {}
};
portal2 = {
name = HungerGames.portal2.Name;
teleportTo = workspace.Part.CFrame;
playerTable = {}
}
}
}
}
return module
Server Script:
-- // Modules
local ZoneModule = require(game:GetService("ReplicatedStorage").Modules:FindFirstChild("Zone"))
local teleportModule = require(script.Parent)
-- // Services
local teleportService = game:GetService("TeleportService")
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
.5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut,
0,
true,
0)
local valuesToTween = {
Position = UDim2.new(0.5,0,0.3,0),
TextColor3 = Color3.new(0.14902, 1, 0),
Size = UDim2.new(1.1, 0,1.1, 0)
}
-- // Variables
local hubPortal = workspace.Hub.MiniGames
local textAmount = 0
local maxAmount = 0
-- // Functions
for index, teleportPlaces in pairs(teleportModule.TeleportPlaces) do
for _, HG in pairs(teleportPlaces.HungerGames) do
for _, portal in pairs(hubPortal:GetDescendants()) do
local hitBox = portal:FindFirstChild("hitBox")
if hitBox then
local zone = ZoneModule.new(hitBox)
local plrTable = HG.playerTable -- Here
zone.playerEntered:Connect(function(plr)
if hitBox.Parent.Name == HG.name then
table.insert(plrTable, plr) -- And here
if #plrTable >= maxAmount then
if hitBox.Parent.Name == HG.name then
plr.Character:PivotTo(HG.teleportTo)
end
end
end
end)
zone.playerExited:Connect(function(plr)
table.remove(plrTable, plrTable[plr])
print(plrTable)
end)
end
end
end
end