Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i give everyone a trail on-join and not just to the first person?

ServerScriptService

function Join(p)
local function Char(c)
local trail = script.Trail:Clone()
trail.Parent = c.Head
local A0 = Instance.new("Attachment",c.LeftFoot)
local A1 = Instance.new("Attachment",c.RightFoot)
A0.Name = "Attachment0"
A1.Name = "Attachment1"
trail.Attachment0 = A0
trail.Attachment1 = A1
end
p.CharacterAdded:connect(Char)
end
game.Players.PlayerAdded:connect(Join)

1 answer

✓ 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") -- dont use the parent arg as it is deprecated
	local A1 = Instance.new("Attachment")
	
	A0.Name = "Attachment0"
	A1.Name = "Attachment1"

	trail.Attachment0 = A0
	trail.Attachment1 = A1

	-- parent after setup is complete as it reduces network load
	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

0

ServerScriptService.Trail:22: Expected , got 'end'

0

I tried fixing it myself but unfortunately i wasn't able to.

0

forgot to include function on line 19

0

@YoBoi1337 all fixed

This discussion is preserved as it was. New answers, comments, and votes are closed.