My trail is getting displaced 200 studs for no reason :c

so. i made a footprint trail (like your walking leaves footprints) and put attachments at players feet. It worked really well, except the trail was +200 studs away from players cframe (footprints dont usually appear that far away from you in real life, so its a problem)

aanyway i made some example code to make this effect more visible. If you know anything that causes this or just wanna poke fun at how stupid i am, leave a comment

code in StarterCharacterScripts (like 20 lines of code)
local root = script.Parent:WaitForChild("HumanoidRootPart")
local humanoid = script.Parent:WaitForChild("Humanoid")

-- Setup
local attachment0 = Instance.new("Attachment")
attachment0.Parent = root
local attachment1 = Instance.new("Attachment")
attachment1.Parent = root
local trail = script:WaitForChild("Trail"):Clone()
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = root

game:GetService("RunService").Heartbeat:Connect(function()
	attachment0.CFrame = root.CFrame + Vector3.new(25,0,0) 
	attachment1.CFrame = root.CFrame
	
	if humanoid.FloorMaterial == Enum.Material.Sand and humanoid.MoveDirection.Magnitude > 0 then trail.Enabled = true
	else trail.Enabled = false end
end)

local root = script.Parent:WaitForChild("HumanoidRootPart")
local humanoid = script.Parent:WaitForChild("Humanoid")

-- Setup
local attachment0 = Instance.new("Attachment")
attachment0.Parent = root
local attachment1 = Instance.new("Attachment")
attachment1.Parent = root
local trail = script:WaitForChild("Trail"):Clone()
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = root

game:GetService("RunService").Heartbeat:Connect(function()
	attachment0.Position = root.Position + Vector3.new(25,0,0) 
	attachment1.Position = root.Position
	
	if humanoid.FloorMaterial == Enum.Material.Sand and humanoid.MoveDirection.Magnitude > 0 then trail.Enabled = true
	else trail.Enabled = false end
end)

Attachments do not need updating every frame as they remain in a locked offset from their parent Part.

Remove the attachment CFrame set from the Heartbeat and reduce the offset from 25 to 2.5

local root = script.Parent:WaitForChild("HumanoidRootPart")
local humanoid = script.Parent:WaitForChild("Humanoid")

-- Setup
local attachment0 = Instance.new("Attachment")
attachment0.Parent = root
local attachment1 = Instance.new("Attachment")
attachment1.Parent = root
local trail = script:WaitForChild("Trail"):Clone()
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = root

attachment0.Position = root.Position + Vector3.new(25,0,0) 
attachment1.Position = root.Position

game:GetService("RunService").Heartbeat:Connect(function()
	if humanoid.FloorMaterial == Enum.Material.Sand and humanoid.MoveDirection.Magnitude > 0 then trail.Enabled = true
	else trail.Enabled = false end
end)

this is the fixed code of the fixed code as i forgot that attachments are locked thanks to @WingItMan for reminding me

The attachment position is relative to the parent part, do this instead:

local root = script.Parent:WaitForChild("HumanoidRootPart")
local humanoid = script.Parent:WaitForChild("Humanoid")

-- Setup
local attachment0 = Instance.new("Attachment")
attachment0.Parent = root
local attachment1 = Instance.new("Attachment")
attachment1.Parent = root
local trail = script:WaitForChild("Trail"):Clone()
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
trail.Parent = root

game:GetService("RunService").Heartbeat:Connect(function()
	attachment0.WorldCFrame = root.CFrame + Vector3.new(25,0,0) 
	attachment1.WorldCFrame = root.CFrame
	
	if humanoid.FloorMaterial == Enum.Material.Sand and humanoid.MoveDirection.Magnitude > 0 then trail.Enabled = true
	else trail.Enabled = false end
end)
1 Like

so roblox actually developed 2 separate cframe/position types called world cframe and position just because they wanted attachments to be set relative to parent

genius api decisions right there, 11/10

i dont think i would have figured this out without you lol. thanks to everyone else who responded too, you guys are awesome

1 Like