local teleporterFolder = mapInstance:FindFirstChild("Teleporters")
if not teleporterFolder then warn("no teleport folder") return end
local teleporters = {}
for _, part in ipairs(teleporterFolder:GetDescendants()) do
if part:IsA("BasePart") and game:GetService("CollectionService"):HasTag(part, "Teleporter") then
table.insert(teleporters, part)
part:SetAttribute("Occupied", false)
end
end
if #teleporters == 0 then warn("no teleports available") return end
for _, player in pairs(self.Participants) do
local character = player.Character or player.CharacterAdded:Wait()
local root = character:FindFirstChild("HumanoidRootPart") or character:WaitForChild("HumanoidRootPart", 2)
if character and root then
local randomNumber = math.random(1, #teleporters)
local randomTeleporter = teleporters[randomNumber]
if not randomTeleporter:GetAttribute("Occupied") then
game:GetService("RunService").Heartbeat:Wait()
warn("teleported: "..player.Name)
local designatedCFrame = CFrame.new(randomTeleporter.Position + Vector3.new(0, 5, 0))
character.PrimaryPart.CFrame = designatedCFrame
-- rest of the script
I've tried manually changing the character's primarypart and pivotTo but on rare occassions it doesn't tp the player to the designated CFrame.
I really don't know if there's anything wrong with it, there's no errors at all
Please help!