I've created a spawn system that finds the magnitude of all the player's characters humanoidrootparts and spawns you away from them if they're too close to a spawn point.
It works in theory, but in practice it "works" until you spawn directly on a player.
PROBLEM
I've narrowed down the problem to the fact that whenever it finds distancefromplayer it's taking EVERY player's position and subtracting it from the part's position then finding the magnitude.
Meaning if there are 3 players in a game and Player1 is on spawn 3 but Player2 is across the map. When Player3 spawns, he could potentially spawn direction on top of Player1 because the magnitude between the two is greater than the min. BUT if both Player1 and Player2 are on spawn 3 then Player 3 has NO chance what so ever to spawn on that spawn point.
local sspawn = {} local mindistance = 80 local availiablespawns = 0 local players = game.Players local children = {} for i,v in pairs(players:GetChildren())do if v.Name ~= player.Name then table.insert(children,v.Name) end end for i, g in pairs (spawns:GetChildren()) do if g:IsA("Part") then if children[1] == nil then else for i = 1,#children do local kiddo = game.Players:FindFirstChild(children[i]).Character.HumanoidRootPart local distancefromplayer = (g.Position - kiddo.Position).Magnitude if distancefromplayer >= mindistance then table.insert(sspawn, g.Name) print(player.Name.." spawns", "Distance: "..distancefromplayer,"Spawn: "..g.Name) availiablespawns = math.ceil(#sspawn/#children) end end end end end