-- # CODE BELOW # --
-- ^    Do not change anything else


local GoreFolder = game.ReplicatedStorage["Gore by Leveled Development"];
local Core = require(GoreFolder.Modules.Core);

function Asset(Player)
	local Character = Player.Character;
	local Gibs = script.Gibs;
	local GibParts = {
		["Head"] = {Gibs["Head"]:Clone(), Character["Head"]},
		["LeftArm"] = {Gibs["LeftArm"]:Clone(), Character["Left Arm"]},
		["RightArm"] = {Gibs["RightArm"]:Clone(), Character["Right Arm"]},
		["LeftLeg"] = {Gibs["LeftLeg"]:Clone(), Character["Left Leg"]},
		["RightLeg"] = {Gibs["RightLeg"]:Clone(), Character["Right Leg"]}
	};
	
	for Int, Parts in pairs(GibParts) do
		Parts[1].Parent = Parts[2];
		Parts[1].CFrame = Parts[2].CFrame;
		Core.WeldTo(Parts[2], Parts[1]);
	end;
	
	if not Character:FindFirstChild("Humanoid") then
		repeat wait() until Character:FindFirstChild("Humanoid");
	end;
	if not Character:FindFirstChild("Humanoid"):FindFirstChild("HumanoidDescription") then
		repeat wait() until Character:FindFirstChild("Humanoid"):FindFirstChild("HumanoidDescription");
	end;
	
	GibParts["Head"][1]["Main"].Color = Character.Humanoid.HumanoidDescription.HeadColor;
	GibParts["LeftArm"][1]["Main"].Color = Character.Humanoid.HumanoidDescription.LeftArmColor;
	GibParts["RightArm"][1]["Main"].Color = Character.Humanoid.HumanoidDescription.RightArmColor;
	GibParts["LeftLeg"][1]["Main"].Color = Character.Humanoid.HumanoidDescription.LeftLegColor;
	GibParts["RightLeg"][1]["Main"].Color = Character.Humanoid.HumanoidDescription.RightLegColor;
end;

game.Players.PlayerAdded:Connect(function(Player)
	if not Player.Character then
		Player.CharacterAdded:Wait();
	end;
	Asset(Player);
	while wait() do
		if Player.Character:FindFirstChild("Head") then
			if not Player.Character.Head:FindFirstChild("Head") then
				Asset(Player);
			end;
		end;
	end;
end);
