I dont know why but it wont teleport all players… just one (when one player touches the part I want all to be transported)
local telePart = script.Parent
local TeleportService = game:GetService('TeleportService')
local placeID = (13050238945)
local canTeleport = true
local function otherGame(otherPart)
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player and canTeleport then
canTeleport = false
local ReservedServerAccessCode = TeleportService:ReserveServer(placeID)
TeleportService:TeleportToPrivateServer(placeID, ReservedServerAccessCode, {player})
wait(0.3) --cooldown time
canTeleport = true
end
end
telePart.Touched:Connect(otherGame)
I believe its because you are only checking for one player.
This is what could work (havent tested it, its only example code anyway)
local telePart = script.Parent
local TeleportService = game:GetService('TeleportService')
local placeID = (13050238945)
local canTeleport = true
local function otherGame(otherPart)
local players = game.Players:GetPlayers()
for _, plr in ipairs(players) do
if not canTeleport then return end
canTeleport = false
local ReservedServerAccessCode = TeleportService:ReserveServer(placeID)
TeleportService:TeleportToPrivateServer(placeID, ReservedServerAccessCode, {plr})
task.wait(0.3) --cooldown time
canTeleport = true
end
end
simple, this script, is sending every player who touches it, into a different reserved server… but its a party based game… so I want when one player touches the part. all players in server get sent into the reserved server…
local telePart = script.Parent
local TeleportService = game:GetService('TeleportService')
local placeID = (13050238945)
local canTeleport = true
local function otherGame(otherPart)
local player = game.Players:FindFirstChild(otherPart.Parent.Name)
if player and canTeleport then
canTeleport = false
local ReservedServerAccessCode = TeleportService:ReserveServer(placeID)
TeleportService:TeleportToPrivateServer(placeID, ReservedServerAccessCode, {player})
wait(0.3) --cooldown time
canTeleport = true
end
end
telePart.Touched:Connect(otherGame)
local telePart = script.Parent
local TeleportService = game:GetService("TeleportService")
local placeID = 13050238945
local canTeleport = true
local function otherGame(otherPart)
local player = game:GetService("Players"):GetPlayerFromCharacter(otherPart.Parent)
if player and canTeleport then
canTeleport = false
for _,plr in ipairs(game:GetService("Players"):GetPlayers()) do
local AccessCode = TeleportService:ReserveServer(placeID)
local TeleportOptions = Instance.new("TeleportOptions")
TeleportOptions.ReservedServerAccessCode = AccessCode
coroutine.wrap(function()
local Success,Error = pcall(function()
TeleportService:TeleportAsync(placeID,{plr},TeleportOptions)
end)
if not Success then warn(Error) end
end)
end
task.wait(0.3)
canTeleport = true
end
end
telePart.Touched:Connect(otherGame)
local function otherGame(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") then
pcall(function()
local players = game.Players:GetPlayers()
if canTeleport then
canTeleport = false
local ReservedServerAccessCode = TeleportService:ReserveServer(placeID)
TeleportService:TeleportToPrivateServer(placeID, ReservedServerAccessCode, players)
task.wait(0.3) --cooldown time
canTeleport = true
end
end)
end
end
telePart.Touched:Connect(otherGame)