I’ve been trying to make a system to teleport using a randomized value when a player joins the game.
local Players = game:GetService("Players")
local function PlayerAdded(plr)
local mapspawn = Instance.new("Folder")
mapspawn.Name = "spawnpoint"
local spawnpoint = Instance.new("NumberValue")
spawnpoint.Name = "point"
spawnpoint.Value = math.random(1,7)
spawnpoint.Parent = plr
print(spawnpoint.Value)
end
game.Players.PlayerAdded:Connect(PlayerAdded)
This is the code I used to assign a random variable on spawn. it works as intended
the code i’m working on for the inRound teleport system is as follows
if inRound.Value == true then
for i, plr in pairs(game.Players:GetChildren()) do
local char = plr.Character
local humanRoot = char:WaitForChild("HumanoidRootPart")
for _, plr in Players:GetPlayers() do -- Loop over the player list
local char = plr.Character
local root = char:WaitForChild("HumanoidRootPart") -- Waiting for rootparts will delay other player teleports, might want to make each iteration a different thread
local spawnpoint = plr.spawnpoint.point.Value -- Add value, it is important!
local spawn = game.Workspace.mapspawn:FindFirstChild("spawn"..tostring(spawnpoint)) -- Check if there is an existing spawnpoint (spawn1, spawn2, ...)
if not spawn then continue end -- if there is no spawn go for the next player, might wanna change this logic
root.CFrame = spawn.CFrame -- teleport player!
end
plr.Team = playingTeam
char:WaitForChild("Humanoid").Died:Connect(function()
plr.Team = lobbyTeam
end)
end
else
the else is for a different teleport, which works as intended.