How to attach a part to a player?

Hello developers, I am making a script which makes a player infectious to others, and when the player touches another player it gives them the ability to infect another, and so on. Since this is the first time doing so, I decided to attach an infecting part to the player. But if you have better ways, please tell me. So when I did so, the infecting part just stayed in the same position, and didn’t seem to attach to the player.

local part = script.Parent --the infection part

script.Parent.Touched:Connect(function(part)
	part.BrickColor = BrickColor.new('Bright green')
	part.Parent.UpperTorso.BrickColor = BrickColor.new('Dark orange')
	part.Parent.Shirt.ShirtTemplate = 'http://www.roblox.com/asset/?id=1488865898'
	part.Parent.Pants:Destroy()
	script.Parent.Owch:Play()
	part.Parent.Humanoid.WalkSpeed = 10
	part.Parent.Head.face.Texture = 'http://www.roblox.com/asset/?id=133360891'
	wait(.3)
	
	for _, acc in pairs(part.Parent:GetChildren()) do --destroying accessories
		if acc:IsA('Accessory') then
			acc:Destroy()
		end
	end
	
	local infectionPt = part:Clone() --Cloning the infection part
	infectionPt.Transparency = 1
	infectionPt.Parent = part.Parent --Setting the infection part parent to the Character

I’ve tried attachments, but I have no understanding of how to use them.

Any help/advice would be appreciated, thanks.

1 Like

You can use a Beam instead. Parts would need to be updated every frame until they don’t exist anymore, beams do that automatically.

local b = Instance.new("Beam", script.Parent)
b.Attachment0 = Instance.new("Attachment", script.Parent)
b.Attachment1 = part.Parent:FindFirstChild("WaistRigAttachment", true)
--set properties like color
game:GetService("Debris"):AddItem(b, 1)

Edit: I thought you meant a visual effect to notify the player getting infected, not an invisible touch part to infect other players. To attach the part to the character just do

local w = Instance.new("Weld", part.Parent.HumanoidRootPart)
w.Part0 = w.Parent
w.Part1 = infectionPt
7 Likes