I can't find the error in this script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want to get my script to work.
  2. What is the issue?
    I don’t know where the error is.
  3. What solutions have you tried so far?
    I couldn’t find any solutions.
local highestplayer
			local highestdistance
			if RoundTime == 0 then
				for i,v in pairs(game.Players:GetPlayers()) do
					
				local distance = v:DistanceFromCharacter(SelectedMap.EndPart.Position)
				if v.Team  == game.Teams.Game then
						if v.Character.Completed == false then
							if distance >= highestdistance then
								highestdistance = distance
								highestplayer = v.Name
							end
						end
					end
				end
			local gamePlayers = {}
			for i,v in pairs(game.Players:GetPlayers()) do
				local Number = #gamePlayers + 1
					if v.TeamColor == BrickColor.new("Really red") then
						table.insert(gamePlayers,Number,v)
					end
			end
			local highestplr = game.Players:FindFirstChild(highestplayer)
			highestplr.Team = game.Teams.Lobby
				if #gamePlayers == 1 then
				game.Workspace.Board.SurfaceGui.TextLabel.Text = "Game ended! "..gamePlayers[1].Name.." won the game!"
				wait(5)
				end

Could someone help me with this script I already found out that the error is in this part but I can’t seem to find it.

Can you please send a screenshot of the error?

Thats the problem in the output is nothing but the script stops working

Start at the beginning what is the error ? :thinking:

Maybe that because currently your condition is checked only once but it is functional :

while wait() do
local highestplayer
			local highestdistance
			if RoundTime == 0 then
				for i,v in pairs(game.Players:GetPlayers()) do
					
				local distance = v:DistanceFromCharacter(SelectedMap.EndPart.Position)
				if v.Team  == game.Teams.Game then
						if v.Character.Completed == false then
							if distance >= highestdistance then
								highestdistance = distance
								highestplayer = v.Name
							end
						end
					end
				end
			local gamePlayers = {}
			for i,v in pairs(game.Players:GetPlayers()) do
				local Number = #gamePlayers + 1
					if v.TeamColor == BrickColor.new("Really red") then
						table.insert(gamePlayers,Number,v)
					end
			end
			local highestplr = game.Players:FindFirstChild(highestplayer)
			highestplr.Team = game.Teams.Lobby
				if #gamePlayers == 1 then
				game.Workspace.Board.SurfaceGui.TextLabel.Text = "Game ended! "..gamePlayers[1].Name.." won the game!"
				wait(5)
				end
end

Whenever this is the case just spam prints everywhere and see where it gets. Then you could find a solution after you locate the issue.

1 Like

Thanks that worked the error was in the distance that I had EndPart wrong in the model its just end

1 Like

Glad that could help, that’s what I usually do in these situations and it’s quite effective. If you need help further now that you know the issue you could let us know and I’m sure someone will get back to you.