I would do something along the lines of defining the spawns model first
local Spawns = yourSpawnsModelPath:GetChildren();
then I would create a function to get the randomspawn
function getRandomSpawn()
local ranNum = math.random(1,#Spawns);
local Spawn = Spawns[ranNum];
return Spawn;
end
Then I will create a function to teleport the player to the random spawn
function teleportPlayerToSpawn(player)
if game.Players:FindFirstChild(player) then
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
if hrp then
if getRandomSpawn() then
hrp.CFrame = getRandomSpawn().CFrame * CFrame.new(0,3,0)
end
end
end
end
Then call the function when needed teleportPlayerToSpawn(player) dont forget the player variable pass through the player object.
I am not 100% sure this work neither if it's the best method made it off the spot hope it works! Upvote if it helps! -cc
3 comments
One thing wrong is that
GameInProgessis an object, not a boolean,Yeah I Know about that Thanks Thoe
Get the position of the parts and use math.random