✓ Accepted answer
As you are using PlayerAdded and CharacterAdded it will add the trail to all players that join. I think the issue is that you are not using WaitForChild so the parent of the attachement or trail could be nil.
You should split this code up into an additional function as it is good practice. I would also make use of anonymous function as the Join function is not being used in another place (the join function should also be local).
Lastly use the upper case version of connect as this fits better wit the current Roblox naming conventions.
local function giveTrail(charModel)
local trail = script.Trail:Clone()
local A0 = Instance.new("Attachment")
local A1 = Instance.new("Attachment")
A0.Name = "Attachment0"
A1.Name = "Attachment1"
trail.Attachment0 = A0
trail.Attachment1 = A1
A0.Parent = charModel:WaitForChild('LeftFoot')
A1.Parent = charModel:WaitForChild('RightFoot')
trail.Parent = charModel:WaitForChild('Head')
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(charModel)
giveTrail(charModel)
end)
end)
I hope this helps. Please comment if you have any other questions about this code.
4 comments
ServerScriptService.Trail:22: Expected , got 'end'
I tried fixing it myself but unfortunately i wasn't able to.
forgot to include function on line 19
@YoBoi1337 all fixed