Script cant find char.Torso for trail

Hi im trying to make a player trail and i have tried using many different scripts but every time it fails to find char.Torso or char.Head etc

local Trail = game.ServerStorage["RainbowTrail"]

game.Players.PlayerAdded:Connect(function(plr)
	
	plr.CharacterAdded:Connect(function(char)
		
		local plrTrail = Trail:Clone()
		
		plrTrail.Parent = char.Torso
		
		plrTrail.Attachment0 = char.Head.FaceFrontAttachment
		plrTrail.Attachment1 = char.Torso.WaistBackAttachment	
		
	end)	
end)

Heres the code im using. Does anyone know how to fix this? Thankyou!!

2 Likes

If your character is r15, this will not work
this is the universal way to do it (works with r15 and r6)
if its mainly r6 then change the rootpart below to torso if you want

local Trail = game.ServerStorage["RainbowTrail"]

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local RootPart = char:WaitForChild('HumanoidRootPart')
		local Head = char:WaitForChild('Head')
		local plrTrail = Trail:Clone()
		plrTrail.Parent = RootPart
		plrTrail.Attachment0 = Head.FaceFrontAttachment
		plrTrail.Attachment1 = RootPart.WaistBackAttachment	
	end)	
end)
2 Likes

okay thankyou! I put this script in and it comes up with this 11:57:38.050 WaistBackAttachment is not a valid member of Part “t3h1dy.HumanoidRootPart” - Server - RainbowTrail:10

1 Like
local Trail = game.ServerStorage["RainbowTrail"]

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local RootPart = char:WaitForChild('HumanoidRootPart')
		local Head = char:WaitForChild('Head')
		local plrTrail = Trail:Clone()
		plrTrail.Parent = RootPart
		plrTrail.Attachment0 = Head.FaceFrontAttachment
		plrTrail.Attachment1 = RootPart.RootAttachment
	end)	
end)
2 Likes

now it says this " RootPartAttachment is not a valid member of Part “t3h1dy.HumanoidRootPart”

im not sure what this means

2 Likes

replace the attachment1 line with this

local attachment1 = Instance.new('Attachment', RootPart)
Attachment1.Visible = false
Attachment1.CFrame = CFrame.new(0, -1, 0.5, 1, 0, 0, 0, 1, 0, 0, 0, 1)
plrTrail.Attachment1 = attachment1
1 Like

alright i have been thinking for quite a while now but here u go

local Trail = game.ServerStorage["RainbowTrail"]

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Head = char:WaitForChild('Head') -- will wait until the head is loaded, at that time the code below will be yielded by this function, using waitforchild on something that doesnt exist will yield infinitely
		local Torso = char:FindFirstChild('Torso')
		local LowerTorso = char:FindFirstChild('LowerTorso') -- both has waistbackattachment
		local plrTrail = Trail:Clone()
		if Torso then
			plrTrail.Parent = Torso
			plrTrail.Attachment1 = Torso.WaistBackAttachment
		else if LowerTorso then
				plrTrail.Parent = LowerTorso
				plrTrail.Attachment1 = LowerTorso.WaistBackAttachment
			end
		end
		plrTrail.Attachment0 = Head.FaceFrontAttachment
	end)	
end)
1 Like

Hi that code doesnt give any errors but still doesnt show a trail? I dont know whats wrong with it haha

The problem was the character wasn’t fully loaded yet
Adding a wait at the start fixed it…

local Trail = game.ServerStorage["RainbowTrail"]

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		task.wait()
		
		local Head = char:FindFirstChild('Head') -- will wait until the head is loaded, at that time the code below will be yielded by this function, using waitforchild on something that doesnt exist will yield infinitely
		local Torso = char:FindFirstChild('Torso')
		local LowerTorso = char:FindFirstChild('LowerTorso') -- both has waistbackattachment
		local plrTrail = Trail:Clone()
		if Torso then
			plrTrail.Parent = Torso
			plrTrail.Attachment1 = Torso.WaistBackAttachment
		elseif LowerTorso then
				plrTrail.Parent = LowerTorso
				plrTrail.Attachment1 = LowerTorso.WaistBackAttachment
		end
		plrTrail.Attachment0 = Head.FaceFrontAttachment
	end)	
end)

if not Player:HasAppearanceLoaded() then Player.CharacterAppearanceLoaded:Wait() end
To yield the script until the player’s character’s appearance has loaded.

2 Likes