Hey, I’m trying to set the players spawn location when they first join, but I have 8 spawns I want them to spawn on one of them randomly, but I don’t know how to do this.
I have wrote a script to set their spawn but it only works with 1 spawn location, I cant make is so that there is a random chance of them spawning at any one of the eight spawn locations.
Here is my script:
local SpawnLocs = game.Workspace.SpawnLocs:GetChildren()
local function f1(v1)
v1.RespawnLocation = SpawnLocs[math.random(1, #SpawnLocs)]
end
game.Players.PlayerAdded:Connect(function(v1)
f1(v1)
v1.Character.Humanoid.Died:Connect(function()
f1(v1)
end)
end)
Try, Store an object spawn in a table by assigning the keyvalue pair the key with a number, and using math.random to randomly number the key, you’ll get a random spawn object.
like
Do you get any errors ?
And instead of that you can try this.
Like remove all the respawn points and put a part in place of them, then put this script in the server script
local SpawnLocs = game.Workspace.SpawnLocs:GetChildren()
local function f1(v1)
v1.Character.HumanoidRootPart.CFrame = SpawnLocs[math.random(1, #SpawnLocs)].CFrame
end
game.Players.PlayerAdded:Connect(function(v1)
f1(v1)
v1.Character.Humanoid.Died:Connect(function()
f1(v1)
end)
end)