Hi, i am making a round based game and when all players are gone the round would reset.

It completely ignores the playerremoving function, it does not print and the value is true.

I asked something like this earlier but now this has appeared, please help!

db = true
local roundinprogress = game.Workspace.Game.Scripts.RoundInProgress
local aliveplayers = game.Workspace.Game.Scripts.AlivePlayers
game.Players.PlayerAdded:Connect(function(player)
	roundinprogress.Changed:Connect(function()
		if roundinprogress.Value == true and player.Character:WaitForChild("IsInRound").Value == false then
			local map = game.Workspace:WaitForChild("Map")
			player.Character.HumanoidRootPart.CFrame = map.TeleportPart.CFrame
			aliveplayers.Value = aliveplayers.Value + 1
			player.Character.IsInRound.Value = true
			player.PlayerGui.MapGui.Frame.MapName.Text = map.MapName.Value
			wait()
			player.Character.Humanoid.PlatformStand = false
			player.Character.Humanoid.Jump = true
			print("Teleported player")
		    elseif roundinprogress.Value == false and player.Character:WaitForChild("IsInRound").Value == true then
			player:LoadCharacter()
		end
	end)
end)

game.Players.PlayerAdded:Connect(function(player) --Remove player from round, died
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid.Died:Connect(function()
			if character:WaitForChild("IsInRound").Value == true then
				local aliveplayers = game.Workspace.Game.Scripts.AlivePlayers
				aliveplayers.Value = aliveplayers.Value - 1
				print("Removed one alive player, player has died")
			end
		end)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player) --Remove player from round, left
	player.CharacterRemoving:Connect(function(character)
		local isinround = character:WaitForChild("IsInRound")
		if isinround.Value == true then isinround.Value = false
			local aliveplayers = game.Workspace.Game.Scripts.AlivePlayers
			aliveplayers.Value = aliveplayers.Value - 1
			print("Removed one alive player, player has left")
		end
	end)
end)


4 comments

0

I believe it is because you are trying to run your code within CharacterRemoving. If I am correct, the code won't be fired because it won't initiate until the player leaves, which by then his character is already destroyed. Try running the code purely within PlayerRemoving

0

If i do that it never can find the isinround value because the character is gone? (Sorry for bad english)

0

You can store the IsInRound value within the player itself, or you can even create a table of players in a round, and see if player is inside that table.

0

alright, didnt think bout that. Thanks!