Hello! I am new to scripting and I found some bugs in one of my scripts: 1: In some rounds only some players get swords or nobody 2:It wont tp us to map only some players when round finish 3: the status like intermission wont show up Can you tell me what is wrong and how can i repair? I have with -- the parts it will be easier

there is the script:

-- Defie variables

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerStorage = game:GetService("ServerStorage")

local MapsFolder = ServerStorage:WaitForChild("Maps")

local Status = ReplicatedStorage:WaitForChild("Status")

local GameLength = 50

local reward = 50

-- Game loop

while true doitForChild("Maps")

local Status = ReplicatedStorage:WaitForChild("Status")

local GameLength = 50

	
	Status.Value = "Waiting for enough players"
	
	repeat wait(1) until game.Players.NumPlayers >= 2
	
	Status.Value = "Intermission"
	
	wait(10)
	
	local plrs = {}
	
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			table.insert(plrs,player) -- Add each player into players table	
		end
	end
	
	wait(2)
	
	local AvailibleMaps = MapsFolder:GetChildren()
	 
	local ChosenMap = AvailibleMaps[math.random(1,#AvailibleMaps)]
	
	Status.Value = ChosenMap.Name.." Chosen"
	
	local ClonedMap = ChosenMap:Clone()
	ClonedMap.Parent = game.Workspace
	
	-- Teleport players in map
	
	local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
	
	if not SpawnPoints then
		print("You do not have spawnpoints")
	end
	
	local AvailableSpawnPoints = SpawnPoints:GetChildren()
	
	for i, player in pairs(plrs) do
		if player then
			character = player.Character
			
			if character then
				-- teleport them
				
				function teleportPlayers()
	    for i, player in ipairs(game.Players:GetChildren()) do
	    --Make sure the character exists and its HumanoidRootPart exists
	   if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
	 
	             player.Character.HumanoidRootPart.CFrame = game.Workspace.TeleportPlace.CFrame + Vector3.new(0, i * 5, 0)
	     --add an offset of 5 for each character
	        end
	    end
	end

				
				
				--give them a sword
				
				local Sword = ServerStorage.Sword:Clone()
				Sword.Parent = player.Backpack
				
				local GameTag = Instance.new("BoolValue")
				GameTag.Name = "GameTag"
				GameTag.Parent = player.Character
				
			else
				--there is no character
				if not player then
					table.remove(plrs,i)
				end
			end
		end
	end
	
	
	Status.Value = "Get ready to play!"
	
	wait(2)
	
	for i = GameLength,0,-1 do
		
		for x, player in pairs(plrs) do
			if player then
				
				character = player.Character
				
				if not character then
					--left the game
					table.remove(plrs,x)
				else
					if character:FindFirstChild("GameTag") then
						-- they are alive
						print(player.Name.." is still in the game")
					else
						--they are dead
						table.remove(plrs,x)
					end
				end
			else
				table.remove(plrs,x)
				print(player.Name.."has been removed")
			end
		end
		
		Status.Value = "There re "..i.."secconds remaining"
		
		if #plrs == 1 then
			--last person standing
			Status.Value = "The winner is "..plrs[1].Name
			plrs[1].leaderstats.Bucks.Value = plrs[1].leaderstats.Bucks.Value + reward
			break
		elseif #plrs == 0 then
			Status.Value = "Nobody won"
			break
		elseif i == 0 then
			Status.Value = "Time up!"
			break
		end
		
		wait(1)
	end
		
	print("End of game!")
	
	wait(2)
	
	for i,player in pairs(game.Players:GetPlayers()) do
		character = player.Character
		
		if not character then
			--ignore them
		else
			if character:FindFirstChild("GameTag") then
				character.GameTag:Destroy()
			end
			
			if player.Backpack:FindFirstChild("Sword") then
				player.Backpack.Sword:Destroy()
			end
			
		end
		
		player:LoadCharacter()
		
		Status.Value = "Game ended!"
		
		wait(2)
	end
	
		ClonedMap:Destroy()	
end

5 comments

0

please fix formatting

0

So how i do that, because you know i don't know... what i should change

0

what part is assigning the swords

0

So as i said i don't really know but the part is named handle but the tool is names Sword

0

I can invite someone in my roblox studio if you really can help me