How to make/use a trail

Hello developers! In this my first tutorial I will show you how to make a trail, I will show you some different methods (no gamepass, with gamepass, admins only, on sword).

  1. Insert a Trail in ServerStorage
  2. Customize it as you want (change color, change lenght, etc.)
  3. Insert a Script in ServerScriptService

Now what you need to decide is if make a Trail that require a gamepass or a Trail that doesen’t require any gamepass.

No gamepass

Open the Script we’ve made before and write this into it:

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local Trail = game.ServerStorage.Trail:Clone() --here we create the variable of the Trail we've made at the beginning
        Trail.Parent = char.Head --here we set the Parent of the Trails as the Head of the player's character
        local attachment0 = Instance.new("Attachment") --here we create an attachment that is needed to connect the Trail to the Head of the player
        attachment0.Parent = char.Head --here we set the parent of the attachment as the player's head
        attachment0.Name = "Attachment0" --here we change the name of the attachment
        local attachment1 = Instance.new("Attachment") --here we create another attachment
        attachment1.Parent = char.HumanoidRootPart --here we set the parent of the attachment as the player's HumanoidRootPart
        attachment1.Name = "Attachment1" --here we change the name of the attachment
        Trail.Attachment0 = attachment0 --here we set the trail's attachment0 as the attachment0 we've made before
        Trail.Attachment1 = attachment1 --here we set the trail's attachment1 as the attachment1 we've made before
    end)
end)
With gamepass
  local MarketplaceService = game:GetService("MarketplaceService")

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		if (MarketplaceService:UserOwnsGamePassAsync(player.UserId, 0)) then --change 0 with the ID of your gamepass
			local Trail = game.ServerStorage.Trail:Clone() --here we create the variable of the Trail we've made at the beginning
			Trail.Parent = char.Head --here we set the Parent of the Trails as the Head of the player's character
			local attachment0 = Instance.new("Attachment") --here we create an attachment that is needed to connect the Trail to the Head of the player
			attachment0.Parent = char.Head --here we set the parent of the attachment as the player's head
			attachment0.Name = "Attachment0" --here we change the name of the attachment
			local attachment1 = Instance.new("Attachment") --here we create another attachment
			attachment1.Parent = char.HumanoidRootPart --here we set the parent of the attachment as the player's HumanoidRootPart
			attachment1.Name = "Attachment1" --here we change the name of the attachment
			Trail.Attachment0 = attachment0 --here we set the trail's attachment0 as the attachment0 we've made before
			Trail.Attachment1 = attachment1 --here we set the trail's attachment1 as the attachment1 we've made before
		end
	end)
end)

Do you want to add a Trail to your sword? Nothing simpler!

Add a Trail to a sword
  1. Get a sword model and add the two red parts in the images and set the CanCollide to false
    Cattura.PNG

  2. Group the parts and add a WeldCostraint into them, Set the Part0 as the parent part and the Part1 as the handle:
    Cattura

  3. Insert a Trail in the UpperPart, customize it as you want and add an Attachment for each of the red parts:
    Cattura

  4. Set the Attachment0 of the trail as the UpperAttachment and the LowerAttachment as the Attachment1:

Now everything is ready. You can set the transparency of the red parts to 1.

And now we have a sword with a rainbow trail:

Wait what? Do you want a trail for admins only? Nothing simpler!

Trail for admins only

Insert a Script in ServerScriptService and write this:

local admins = { --here we create a table with the IDs of the admins
	1631420942 --Change this ID with yours, you can add another one by inserting a comma after it, going to the head and inserting another one
}

        game.Players.PlayerAdded:Connect(function(player)
        	player.CharacterAdded:Connect(function(char)
        		if table.find(admins, player.UserId) then --here we check if the player that join is an admin searching in the table we've made before
        			local trail = game.ServerStorage.Trail:Clone() --here we create the variable of the Trail we've made at the beginning
        			trail.Parent = char.Head --here we set the Parent of the Trails as the Head of the player's character
        			local attachment0 = Instance.new("Attachment") --here we create an attachment that is needed to connect the Trail to the Head of the player
                    attachment0.Parent = char.Head --here we set the parent of the attachment as the player's head
        			attachment0.Name = "Attachment0" --here we change the name of the attachment
        			local attachment1 = Instance.new("Attachment") --here we create another attachment
                    attachment1.Parent = char.HumanoidRootPart --here we set the parent of the attachment as the player's HumanoidRootPart
        			attachment1.Name = "Attachment1" --here we change the name of the attachment
        			trail.Attachment0 = attachment0 --here we set the trail's attachment0 as the attachment0 we've made before
        			trail.Attachment1 = attachment1 --here we set the trail's attachment1 as the attachment1 we've made before
        		end
        	end)
        end)

This is all for this tutorial, I hope this has helped you! :smile:

25 Likes

Oh, ok i’m sorry this is my first tutorial :sweat_smile:

3 Likes

Well, this is still helpful for me. Thanks.

2 Likes

Definitely helps. Could this be added to tools?

Nvm I think I figured it out, thanks though

1 Like

technically there is. if you read it, you will see he has added comments for what the lines of code do. correct me if i’m wrong…

this line is probably at the wrong place

1 Like

Oh, the formatting text of the forum… :roll_eyes:

When you make a gamepass for it, example: a red trail or a blue trail, and a player purchases both. How do you let them choose which one is activated?

You could create a gui that activate one and deactivate the other.

Yes it’s the same thing I thought.

Am i able to duplicate the script for more trails?

You don’t need two parts for the sword trail, you can just put the attachments and beam into the sword itself abd it’ll work the same

Yes but disable the others to avoid trails overlap, also you could handle multiple trails with a Gui using the same script.

1 Like

ok, im trying to create a gamepass shop with trails in it and you will be able to equip and unequip the trails you own, will your script work? Or do i need to make/find a different one.

The script won’t work as it is now, you will need yo adjust it for your case

Ok, The thing is that I am very bad with scripting so can you link or teach me what to add to the script.

and how about you make a script for badge only trails

You must check if the user owns the badge using the badgeservice

If BadgeService:UserHasBadgeAsync(userId, badgeId) then

Once you check it you give the trail

Also I would suggest not checking for badges since players could just delete the badge from their inventory

Actually I can’t, I’m on vacation and I don’t have my pc here so it’s hard to write a code on mobile