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

How do I add an object to the player on spawn?

I want to put two attachments in the local player's HumanoidRootPart and a Trail in the local player (I'm making a shift-to-sprint function that enables a trail behind the player when the sprint is active). How would I do this? I don't want to use a custom playermodel, so would I use a LocalScript in the starterpack?

EDIT: Here's what I've got so far.

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        local attach1 = Instance.new("Attachment")
        attach1.Position = Vector3.new(0,2.25,0)
        attach1.Parent = Character.HumanoidRootPart

		local attach2 = Instance.new("Attachment")
        attach2.Position = Vector3.new(0,-2.25,0)
        attach2.Parent = Character.HumanoidRootPart

		local trail = Instance.new("Trail")
		trail.Attachment0 = attach1
		trail.Attachment1 = attach2
		trail.Parent = Character
    end)
end)

3 comments

0

Almost forgot. Thank you in advance!

0

You can send your script?

0

I've got this as a localscript in the starterpack. Does it matter what it is or where it is?

2 answers

Sorry for wasting everyone's time. I figured it out.

3 comments

0

Do not put a comment in the answer area.

0

lol legend

0

ps its an answer

Remember, all scripts in LocalScript not give a Object to all players! and not work game.Players.PlayerAdded in LocalScript

you script are good. You just need to put this script in Server Script.

game.Players.PlayerAdded does not work in LocalScript. You need to use this in a Server Script in Workspace or ServerScriptService.

You can see more here: Roblox Wiki - PlayerAdded

Summary: Put your script in Server Script. and put the Server Script in Workspace or ServerScriptService

Hope it helped! :)

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