When i change this value (.magnitude>500) the script stop working and there is no clear reason why.
if x[i]:IsA("SpawnLocation") then
if (x[i].Position-baseplate.Position).magnitude>500 then -- If a spawn is >500 studs from the baseplate then,
x[i]:Destroy() -- delete it.
else
the whole script
PlayersRequiredToStartAwardingPoints=1
local y=workspace:GetDescendants()
for s=1,#y do
if y[s].Name=="Doomspires" then
-- GAME VALUES --
local GVF=Instance.new("Folder")
GVF.Parent=y[s]
GVF.Name="GameValues"
local TF=Instance.new("Folder")
TF.Parent=GVF
TF.Name="Teams"
local TeamsLeftInt=Instance.new("IntValue")
TeamsLeftInt.Parent=GVF
TeamsLeftInt.Name="TeamsLeft"
local k=y[s]:GetChildren()
for o=1,#k do
if not k[o]:IsA("Script") then -- Only make values
if k[o].Name~="GameValues" then
if k[o].Name~="Holder" then
local BCV=Instance.new("BrickColorValue")
BCV.Parent=TF
BCV.Name=k[o].Name
local SpawnVal=Instance.new("IntValue")
SpawnVal.Parent=BCV
SpawnVal.Name="Spawns"
local u=k[o]:GetDescendants()
for h=1,#u do
if u[h]:IsA("SpawnLocation") then
BCV.Value=u[h].TeamColor
SpawnVal.Value=#u[h].Parent:GetChildren()
end
end
end
end
end
end
TeamsLeftInt.Value=#TF:GetChildren()
-- GAME CONTROL --
local x=y[s]:GetDescendants()
for i=1,#x do
if x[i]:IsA("SpawnLocation") then
x[i].AncestryChanged:connect(function(SpawnPart) -- Technically this just checks for changes in parentage, but it also works when the spawn falls into the void.
local c=y[s]:WaitForChild("GameValues",1):WaitForChild("Teams",1):GetChildren() -- values are being created inscript, using WaitForChild to avoid syntax errors
for g=1,#c do -- Begin scanning in order to associate the GameValues with the actual game
if SpawnPart:IsA("SpawnLocation") then
if c[g].Value==SpawnPart.TeamColor then -- If one of the BrickColorValues in GameValues.Teams is equal to the SpawnLocation's TeamColor (NOT the spawn's BrickColor), then ...
c[g]:WaitForChild("Spawns",1).Value=c[g]:WaitForChild("Spawns",1).Value-1 -- ... subtract that team's spawn value in GameValues.Teams.[TeamName]. Remember, this is if one of the spawns is deleted.
if c[g]:WaitForChild("Spawns",1).Value==0 then -- If you have no spawns left, then you lose.
y[s]:WaitForChild("GameValues",1):WaitForChild("TeamsLeft",1).Value=y[s]:WaitForChild("GameValues",1):WaitForChild("TeamsLeft",1).Value-1 -- This is vital to the game ending as a whole.
game.Teams:FindFirstChild(c[g].Name).AutoAssignable=false
local msg=Instance.new("Message")
msg.Text=c[g].Name.." TEAM has been eliminated!"
msg.Parent=workspace
end
end
end
if y[s]:WaitForChild("GameValues",1):WaitForChild("TeamsLeft",1).Value==1 then -- If 1 team remains then...
local e=y[s]:WaitForChild("GameValues",1):WaitForChild("Teams",1):GetDescendants()
for j=1,#e do
if e[j].Name=="Spawns" then
if e[j].Value~=0 then -- ... find that team, whose spawn does NOT have a value of zero ...
wait(4)
local msg=Instance.new("Message")
msg.Text=e[j].Parent.Name.." TEAM has won the game!"
local p=game.Players:GetChildren()
for q=1,#p do
if #p>=PlayersRequiredToStartAwardingPoints then -- if there's more than 4 people playing lmao
if e[j].Parent and p[q].TeamColor==e[j].Parent.Value then
pcall(function() game:GetService("PointsService"):AwardPoints(p[q].userId, 100) end)
p[q].Tickets.Tix.Value = p[q].Tickets.Tix.Value +50
end
end
end
msg.Parent=workspace
script.RegenScriptLocation.Value.Signal.Value=true -- ... regen the map using the Changed function.
return
end
end
end
end
end
end)
end
end
end
end
-- All the stuff below until the while loop was probably not written by Hybridtheory00. That's the guy who was selling the free model where this came from but I doubt he made it.
-- Anyways, this is just great! :)
function AssignableTeams()
local assignableTeams = {}
for _, team in pairs(game.Teams:GetTeams()) do
if team.AutoAssignable then
table.insert(assignableTeams, team)
end
end
return assignableTeams
end
script:WaitForChild("ShuffleTeams").OnInvoke = function()
local teams = AssignableTeams()
local numberOfTeams = #teams
local playersList = game.Players:GetPlayers()
local numberOfPlayers = #playersList
-- Quit early if there are no teams, this avoids a divide by zero
if #teams == 0 or #playersList == 0 then
return
end
local playersPerTeam = math.floor(numberOfPlayers / numberOfTeams)
local leftOverPlayers = numberOfPlayers - (playersPerTeam * numberOfTeams)
local teamCount = {}
for _, team in ipairs(teams) do
teamCount[team] = 0
for i = 1, playersPerTeam do
local k = math.random(1, #playersList)
local player = playersList[k]
if player then
player.TeamColor = team.TeamColor
teamCount[team] = teamCount[team] + 1
table.remove(playersList, k)
end
end
end
-- Now place the remaining players
for i = 1, leftOverPlayers do
local k, player = next(playersList)
local teamIndex = math.random(1, #teams)
local team = teams[teamIndex]
if player and teamIndex then
player.TeamColor = team.TeamColor
table.remove(playersList, k)
table.remove(teams, teamIndex)
end
end
end
script:WaitForChild("BalanceTeams").OnInvoke = function()
local playersList = game.Players:GetPlayers()
local teams = AssignableTeams()
local teamCounts = {}
-- Quit early if there are no teams
if #teams == 0 or #playersList == 0 then
return
end
for _, team in pairs(teams) do
teamCounts[team] = 0
for _, player in pairs(playersList) do
if player.TeamColor == team.TeamColor then
teamCounts[team] = teamCounts[team] + 1
end
end
end
while true do
local smallestTeam = next(teamCounts)
local largestTeam = smallestTeam
-- Find the smallest and largest teams
for team, count in pairs(teamCounts) do
if count < teamCounts[smallestTeam] then
smallestTeam = team
end
if count > teamCounts[largestTeam] then
largestTeam = team
end
end
-- If the teams are unbalanced/uneven
if (teamCounts[largestTeam] - teamCounts[smallestTeam]) > 1 then
-- Give a player from the largest team to the smallest
for _, player in pairs(playersList) do
if player.TeamColor == largestTeam.TeamColor then
player.TeamColor = smallestTeam.TeamColor
teamCounts[smallestTeam] = teamCounts[smallestTeam] + 1
teamCounts[largestTeam] = teamCounts[largestTeam] - 1
break
end
end
else -- Teams are balanced as well as they can be
return
end
end
end
while wait(10) do
local p=game.Players:GetPlayers()
if workspace:FindFirstChild("Baseplate") then
local baseplate=workspace.Baseplate
x=workspace.Doomspires:GetDescendants()
local spawns=0
for i=1,#x do
if x[i]:IsA("SpawnLocation") then
if (x[i].Position-baseplate.Position).magnitude>500 then -- If a spawn is >500 studs from the baseplate then,
x[i]:Destroy() -- delete it.
else
spawns=spawns+1
end
end
end
if spawns<=0 then
warn("Game might have broke, regenerating")
script.RegenScriptLocation.Value.Signal.Value=true
end
else
for i=1,#p do
p[i]:Kick("Possible exploit, shutting down server")
end
end
end