-- Check if character is there

if script.Owner.Value.Character ~= nil and script.Owner.Value.Character:FindFirstChild("Humanoid") then
	
	-- Listen for invisibility activation
	local debounce = false
	local event = game.ReplicatedStorage.Interactions.Server.Perks.MakeInvisible.OnServerEvent:connect(function(plr)
		
		-- Make sure correct player
		if not debounce and script.Owner.Value.Character ~= nil and plr == script.Owner.Value then
			debounce = true
			
			-- Tell all playing players to make murderer invisible
			local playingPlrs = game.ServerScriptService.RoundManager.GetPlayersInGame:Invoke()
			for n, i in pairs(playingPlrs) do
				if i == script.Owner.Value then
					table.remove(playingPlrs, n)
					break
				end
			end
			for _, i in pairs(playingPlrs) do
				game.ReplicatedStorage.Interactions.Client.ChangeCharacterVisibility:FireClient(i, script.Owner.Value, true)
			end
			
			-- Tell everyone else to make murderer half-transparent
			for _, i in pairs(game.Players:GetPlayers()) do
				local playing = false
				for _, o in pairs(playingPlrs) do
					if o == i then
						playing = true
						break
					end
				end
				if not playing then
					game.ReplicatedStorage.Interactions.Client.ChangeCharacterVisibility:FireClient(i, script.Owner.Value, false)
				end
			end
			
			-- Wait cooldown
			wait(COOLDOWN)
			
			debounce = false
		end
		
	end)
	
	-- Connect character death
	script.Owner.Value.Character.Humanoid.Died:connect(function()
		event:disconnect()
		event = nil
	end)
	
	-- Activate perk for client
	game.ReplicatedStorage.Interactions.Client.Perks.UseInvisibility:FireClient(script.Owner.Value)
	
end
