Hey recently i’ve been working on a dash system with a trail but i’ve been getting “attempt to index nil with PrimaryPart” error and idk why.
here’s the code
game.Players.PlayerAdded:Connect(function(plr)
local character = plr.Character
local root = character.PrimaryPart
local attachment = Instance.new('Attachment')
attachment.Name = "1"
attachment.Parent = root
local attachment2 = attachment:Clone()
attachment2.Name = "2"
attachment2.Parent = root
local trail = Instance.new('Trail')
trail.Name = "trail"
trail.Enabled = false
trail.Parent = root
trail.Attachment0 = attachment
trail.Attachment1 = attachment2
end)
game.Players.PlayerRemoving:Connect(function(plr)
local character = plr.Character
if character then
for _,v in pairs(character:GetChildren()) do
if v.Name == "trail" then
v:Destroy()
end
end
end
end)