Why is this happening?

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
1 Like

So real quick, you might want to take out everything before the while wait(10) do loop so that people aren’t confused by why there is so much irrelevant code being shown here.
I’ll put it here for ease of viewing:

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

So, quickly inferring from your problem, .magnitude>500 would look like this properly spaced out:

.magnitude > 500

Thus, .magnitude > 500 is not just one value, but rather a comparison between two values. If you wanted to change a specific value there, you would probably want to change 500, if anything else.

I might also want to add that a lot of this code is obfusicated and deprecated, but I bet that would be easy to tell from.

2 Likes

When you change it to what? You seem to have posted the version that works.

2 Likes

the thing is that when i change .magnitude > 500 for something like .magnitude > 501 for example or i do literary anything like removing the x[i]:Destroy() part, sections of the script above stops working.
also if i want to change that value what do i do then?

1 Like

yes, what i’m saying is when i change it it stops working for example from .magnitude>500 to
.magnitude>501

So what do you mean when you say that certain parts of the script stops working? Is there anything showing up in the output, or at least anything that can be traced back to the script? Are some spawn locations just not despawning, or is it some completely unrelated part of the script that is breaking?

1 Like

the part that didn’t work was from
pcall(function() game:GetService(“PointsService”):AwardPoints(p[q].userId, 100) end)
downwords

ok i found the problem
For some reason

 pcall(function() game:GetService("PointsService"):AwardPoints(p[q].userId, 100) end) 

was messing with everything else, i dont know why but i removed this part of the code and every thing works fine now.

1 Like

Probably would’ve helped to check the console before assuming what is and isn’t working and why. The console is a powerful tool that points out your errors.

Player points are deprecated and removed and the Wiki should indicate that as well. You therefore cannot use these functions. There are some announcements that touch up on this happening.

1 Like