PlayerRemoving Won't Run

everythings working but the playerRemoving function wont run, but i noticed it does run when the characterRemoving function is removed.
Any Ideas?

local DTS = game:GetService("DataStoreService")
local store = DTS:GetDataStore("ShirtColor")


game.Players.PlayerRemoving:Connect(function (plr)
	plr.CharacterRemoving:Connect(function (char)
		local success, errormessage = pcall(function ()
			store:SetAsync(plr.UserId, char:FindFirstChild("BodyColors").TorsoColor3)
		end)
		if success then
			print("GREEAT")
		else
			warn(errormessage)
		end
	end)
end)


game.Players.PlayerAdded:Connect(function (plr)
	plr.CharacterAdded:Connect(function (char)
		local NewBC = game.ReplicatedStorage.New:Clone()
		local head = char:WaitForChild("Head")
		local decal = head.face
		local BodyColors = char:WaitForChild("Body Colors")

		NewBC.Name = "BodyColors"

		local color

		local success, playerData = pcall(function ()
			return store:GetAsync(plr.UserId)
		end)

		if playerData then
			color = playerData
			print(color)
		else
			color = Color3.fromRGB(math.random(0,256),math.random(0,256),math.random(0,256))
		end


		NewBC.TorsoColor3 = color
		print(decal)
		task.wait(0.3)

		BodyColors:Destroy()
		NewBC.Parent = char

		decal.Texture = "rbxasset://textures/face.png"
		print(decal.Texture)

		for i, part in pairs(char:GetDescendants()) do

			if part:isA("Accessory") then
				part:Destroy()
			end

			if part:isA("Pants") or part:isA("Shirt") then
				part:Destroy()
			end
		end
		if BodyColors then
			BodyColors:Destroy()
		end

		local shirt = Instance.new("ShirtGraphic", char)
		shirt.Graphic = "http://www.roblox.com/asset/?id=296347866"

	end)
end)

Shift the CharacterRemoving code to the PlayerAdded function? CharacterRemoving fires before PlayerRemoving, so your code won’t be able to detect the CharacterRemoving event after the PlayerRemoving event has been fired.

1 Like

This is likely because the character is generally removed first before the player. By the time the game signals that the player is being removed, the character is already gone.

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