Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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)
0
Almost forgot. Thank you in advance! NEXIUS10 13 — 6y
0
You can send your script? yHasteeD 1819 — 6y
0
I've got this as a localscript in the starterpack. Does it matter what it is or where it is? NEXIUS10 13 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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

0
Do not put a comment in the answer area. yHasteeD 1819 — 6y
0
lol legend TheluaBanana 946 — 6y
0
ps its an answer TheluaBanana 946 — 6y
Ad
Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

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! :)

Answer this question