How to make the player's accessories attach to the detached head?

  1. What do you want to achieve?
    I am trying to make the player’s head to fall off when they touch this brick. I am trying to make the accessories attached to the fake head I am cloning.

  2. What is the issue?
    The accessories aren’t attaching properly?

image

  1. What solutions have you tried so far?
    I’ve tried just setting the accessory’s handle position to the cloned head’s position and it worked slightly, but did not work.

Module Script:

local goreModule = {}

---///VARIABLES\\\---
local bloodPart = script:WaitForChild("BloodPart")
local bloodParticles = script:WaitForChild("BloodParticles")
local bloodCache = workspace:WaitForChild("BloodCache")
local tweenService = game:GetService("TweenService")

local goreCache = workspace:WaitForChild("GoreCache")
local chopOffModels = script:WaitForChild("ChopOffModels")
local headChopOff1 = chopOffModels:WaitForChild("HeadChopOff1")
local headChopOff2 = chopOffModels:WaitForChild("HeadChopOff2")

---///LOCAL FUNCTIONS\\\---

--Tween Function
local TweenSize = function(part, duration, style, direction, size)
	tweenService:Create(part, TweenInfo.new(duration, style, direction), {Size = size}):Play()
end

---///MODULE FUNCTIONS\\\---

--Blood Spill Function
function goreModule.Bleed(part, amount, waitTime)
	local clonedBloodParticles = bloodParticles:Clone()
	clonedBloodParticles.Parent = part
	clonedBloodParticles:Emit(amount)
	
	task.wait(.2)
	
	for i = 1, amount/20 do
		
		task.wait(0.1)
		
		local studsAwayFromPartX = math.random(0, 3)
		local studsAwayFromPartZ = math.random(0, 3)
		
		local rayOrigin = part.Position + Vector3.new(studsAwayFromPartX, 4, studsAwayFromPartZ)
		local rayDirection = Vector3.new(0, -100, 0)
		
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {part.Parent}
		raycastParams.FilterType = Enum.RaycastFilterType.Exclude
		raycastParams.IgnoreWater = true

		local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
		
		if raycastResult then
			local clonedBloodPart = bloodPart:Clone()
			clonedBloodPart.Position = raycastResult.Position + Vector3.new(0, .1, 0)
			clonedBloodPart.Parent = bloodCache
			local bloodSize = math.random(1,2)
			TweenSize(clonedBloodPart, .5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, Vector3.new(bloodSize, 0.1, bloodSize))
			local bloodPitch = math.random(0.8, 1.2)
			clonedBloodPart.BloodSound.Pitch = bloodPitch
			clonedBloodPart.BloodSound:Play()
			local removeBloodThread = coroutine.create(function()
				task.wait(waitTime)
				TweenSize(clonedBloodPart, 0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.In, Vector3.new(0.01, 0.01, 0.01))
				task.wait(.5)
				clonedBloodPart:Destroy()
			end)
			coroutine.resume(removeBloodThread)
		end
		
	end
end

function goreModule.ChopOffLimb(character, limb)
	
	if limb == "Head" then
		local clonedHeadChopOff1 = headChopOff1:Clone()
		local clonedHeadChopOff2 = headChopOff2:Clone()

		clonedHeadChopOff1.Parent = goreCache
		clonedHeadChopOff1:SetPrimaryPartCFrame(character:WaitForChild("Head").CFrame)
		clonedHeadChopOff1.Name = character.Name.."'s Head"
		
		clonedHeadChopOff2.Parent = character
		clonedHeadChopOff2:SetPrimaryPartCFrame(character:WaitForChild("HumanoidRootPart").CFrame)
		clonedHeadChopOff1:WaitForChild("Limb").BrickColor = character:WaitForChild("Body Colors").HeadColor
		local headWeld = Instance.new("WeldConstraint")
		headWeld.Parent = character:WaitForChild("HumanoidRootPart")
		headWeld.Part0 = character:WaitForChild("HumanoidRootPart")	
		headWeld.Part1 = clonedHeadChopOff2.PrimaryPart
		character:WaitForChild("Head").Transparency = 1
		character:WaitForChild("Head"):FindFirstChildOfClass("Decal"):Destroy()
		for i, v in pairs(character:GetDescendants()) do
			if v:IsA("Accessory") then
				v.Parent = clonedHeadChopOff1
				v.Handle.Position = clonedHeadChopOff1.Limb.Position + Vector3.new(0,1,0)
				local hatWeld = Instance.new("WeldConstraint")
				hatWeld.Parent = clonedHeadChopOff1.PrimaryPart
				hatWeld.Part0 = clonedHeadChopOff1.PrimaryPart
				hatWeld.Part1 = v.Handle
			end
		end
	end
	
end


return goreModule
1 Like

In the function, you could loop through all the accessories and check for HatAttachment inside of the accessory handle. If the accessory has this then you could put it into the head and then weld it to it. Tell me if you need any help!

That didn’t work. I added a humanoid into the model, and changed the name of the primary part from “Limb” to “Head” expecting it to automatically move the hat’s position when the accessory is parented to the head model. It works in studio when I place a hat inside of the model it instantly snaps the hat’s position where it should be, but in game the hats just roll around on the floor.

image

Excerpt of code in a module script where the error is occurring:

function goreModule.ChopOffLimb(character, limb)
	
	if limb == "Head" then
		local clonedHeadChopOff1 = headChopOff1:Clone()
		local clonedHeadChopOff2 = headChopOff2:Clone()

		clonedHeadChopOff1.Parent = goreCache
		clonedHeadChopOff1:SetPrimaryPartCFrame(character:WaitForChild("Head").CFrame)
		clonedHeadChopOff1.Name = character.Name.."'s Head"
		
		clonedHeadChopOff2.Parent = character
		clonedHeadChopOff2:SetPrimaryPartCFrame(character:WaitForChild("HumanoidRootPart").CFrame)
		clonedHeadChopOff1:WaitForChild("Head").BrickColor = character:WaitForChild("Body Colors").HeadColor
		local headWeld = Instance.new("WeldConstraint")
		headWeld.Parent = character:WaitForChild("HumanoidRootPart")
		headWeld.Part0 = character:WaitForChild("HumanoidRootPart")	
		headWeld.Part1 = clonedHeadChopOff2.PrimaryPart
		character:WaitForChild("Head").Transparency = 1
		character:WaitForChild("Head"):FindFirstChildOfClass("Decal"):Destroy()
		for i, v in pairs(character:GetChildren()) do
			if v:IsA("Accessory") then
				v.Parent = clonedHeadChopOff1
			end
		end
	end
end