How would I check if there's a murderer still ingame if they left before the round starts? (Sorry if I'm unclear)

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 make a system to check if the murderer left before the round started. (at lines 102 to 104 aka over here
						for i, playerInRound in pairs(playing) do
							return scriptfunnyhaha()
						end
  1. What solutions have you tried so far? I can’t find anything on the devforum about it and i tried myself
function scriptfunnyhaha()
	local intermission = 10
	local roundLength = 180

	local inRound = game.ReplicatedStorage.InRound
	local status = game.ReplicatedStorage.Status
	local playing = {}
	local playingTeam = game.Teams.Playing
	local playersingame = 0
	local murdingamechecked = {}
	local lobbyTeam = game.Teams.Lobby

	local murdermodule = require(game.ReplicatedStorage.MurderModule)

	inRound.Changed:Connect(function()

		if inRound.Value == true then

			for i, plr in pairs(game.Players:GetChildren()) do

				local char = plr.Character
				local humanRoot = char:WaitForChild("HumanoidRootPart")



				plr.Team = playingTeam

				char:WaitForChild("Humanoid").Died:Connect(function(playerwhodied)

					plr.Team = lobbyTeam
					table.remove(playing, playerwhodied)

				end)

			end	


		else

			for i, plr in pairs(game.Players:GetChildren()) do
				local char = plr.Character
				local humanRoot = char:WaitForChild("HumanoidRootPart")
				local human = char.Humanoid

				plr.Team = lobbyTeam

				human:UnequipTools()
				plr.Backpack:ClearAllChildren()
			end
		end	
	end)



	local function round()	
		while true do

			local requiredPlayers = 2

			repeat
				wait(1)
				status.Value = "Atleast ".. requiredPlayers.." players are needed to start a round"

			until #game.Players:GetChildren() >= requiredPlayers

			inRound.Value = false


			for i = intermission, 0, -1 do

				status.Value = "Game will start in "..i.." seconds"

				wait(1)
			end
			inRound.Value = true
			for i, plr in pairs(game.Players:GetChildren()) do

				if plr.Team.Name == "Playing" then


					table.insert(playing, plr.Name)


				end	
			end
			playersingame = #game.Players:GetPlayers()
			local msg = murdermodule.ChooseRoles()

			for i = roundLength, 0, -1 do

				status.Value = "Game will end in "..i.." seconds"



				local murdereralive = false
				local nonmurderersalive = false
				local murderer
				print(table.concat(playing, ", ").. " playing")
				print(table.concat(playing, ", ").. " are ingame")
				for i, playerInRound in pairs(playing) do
					if playersingame <= #playing then
						for i, playerInRound in pairs(playing) do
							return scriptfunnyhaha()
						end

					else
						if game.Players:FindFirstChild(playerInRound):WaitForChild("Role").Value == "Murderer" then
							murdereralive = true
							murderer = game.Players:FindFirstChild(playerInRound)
							print("murd is alive")
						elseif game.Players:FindFirstChild(playerInRound):WaitForChild("Role").Value ~= "Murderer" then
							nonmurderersalive = true
							print("innocents are alive")	
						end
					end

				end

				if #playing == 0 then

					status.Value = "Everyone Has Died"
					if game.Workspace:FindFirstChild("GunClone") then
						game.Workspace.GunClone:Destroy()
						if game.Workspace:FindFirstChild("GunClone") then
							game.Workspace.GunClone:Destroy()
						end
					end
					wait(3)
					break

				end
				print(tostring(murdereralive).. "murd")
				print(tostring(nonmurderersalive).. "nonmurd")
				if murdereralive == true and nonmurderersalive == false then
					status.Value = "The Murderer got away with their crimes."
					if game.Workspace:FindFirstChild("GunClone") then
						game.Workspace.GunClone:Destroy()
						if game.Workspace:FindFirstChild("GunClone") then
							game.Workspace.GunClone:Destroy()
						end
					end

					wait(3)
					break
				end

				if murdereralive == false and nonmurderersalive == true then
					status.Value = "The Murderer has been rightfully killed!"
					if game.Workspace:FindFirstChild("GunClone") then
						game.Workspace.GunClone:Destroy()
						if game.Workspace:FindFirstChild("GunClone") then
							game.Workspace.GunClone:Destroy()
						end
					end
					wait(3)
					break
				end

				if nonmurderersalive == true and i == 0 then
					status.Value = "The Murderer took too long and got caught."
					if game.Workspace:FindFirstChild("GunClone") then
						game.Workspace.GunClone:Destroy()
						if game.Workspace:FindFirstChild("GunClone") then
							game.Workspace.GunClone:Destroy()
						end
					end

					wait(3)
					break
				end

				wait(1)
			end
			wait(3)
		end
	end



	spawn(round)
end
scriptfunnyhaha()

Thank you in advance!

Make variable called murderer
local murderer = nil
Now whenever you chose murderer set that variable to the player (when round ends or the murderer gets killed set it back to nil)
This variable should not be in the function but on top of it.

Now at the buttom add a RemovingEvent, then you check if player removing is the murderer this is rather simple:
game:GetService(“Players”).PlayerRemoving:Connect(function(plr)
if plr == murderer then murderer = nil end
end)

Now everything is clear, in the actual inRound script make it so if murderer suddenly changes to nil then yk that the person left the game (sry for any typos and not the best script, I am on mobile)

1 Like

Thank you! It works like a charm! Have an amazing rest of your day/night.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.