Massive thanks to AlvinBLOX for doing this tutorial (https://www.alvinblox.com/)
In this Roblox Rainbow Trail Tutorial I'm going to be showing you how to use the brand new Trail service on Roblox so that you can make this rainbow trail which follows your character around in game.
Today we'll be looking at the brand new trail service on Roblox.
So a trail is made of 3 elements. We need a trail object and then we need two attachments which tells the trail where it's going to start and where it's going to end.
So firstly we're going to make our trail by heading to the serverstorage and we're going to right click on it hover over insert object and click trail this will be the trail which we will replicate into the player once they loaded into the game so we want to make sure it's all set up right now.
So we're going to want to first change the colour of the trail I'm going to have a colour sequence as mine will be a rainbow. So I'm going to click on the 3 dots and then this will allow me to have a sequence of different colours which the trail will iterate through when we're moving.
So I want to start off with a red colour and then i'm going to move it to a yellow, and then i'm going to green, and then i'll have a light blue and then dark blue, and then finally we'll finish with a pink and purple.
I'm just going to make sure that my colours are balanced and are equal so that it doesn't look like one is taking up too much space so the colours are all balanced now that I've got my colour we can click close and that's all that we need to do for now for our trail.
If you want to edit some more properties then go ahead feel free to do so just make sure that you don't touch anything relating to the attachments yet.
So what we're going to want to do now is have a script which will insert this trail and two attachments with it when a new player enters the game.
So we're going to right click on serverscriptservice hover over insert object and hit script and then we'll create two events. One event will wait for the player to join the game and the other will wait for their character to be loaded in.
So to do this we'll say:
*code is on the screen now*
Connect has a capital C
make sure that that end) is added in to your script
If it isn't just add it yourself
and then we're going to pass a parameter of player which the trail will be inserted into if you don't know much about parameters you can view my video which i did in the top right of the screen now on the I, but if you have a good understanding I'll give a quick summary now a parameter is a substitute variable which we use when we don't know the value of something in this case we don't know the name of the player who is going to enter the game so we just use the substitute variable of player.
Although you could call yours anything
So now we have our player parameter we can use this to check for their character to see if it's been added into the game
we use the characteradded event so that we can get their character.
So we're going to say *code on screen*
Make sure your Connect has a capital C
we're going to pass another parameter for the character
which e don't yet know so I'll say 'char'
and then we're going to drop a line, make sure that another end) has been added and then we can get to work
So I’m going to say *code on screen*
So we're referencing the trail which is currently in serverstorage
and we're making a clone of it so we can use this cloned object in our player
So I’m going to say on the next line, *code on screen*
I’m placing the trail in the head of the character you could either place it in the head or in the humanoidrootpart so that it works for both R6 and R15
which are the main roblox body types and then I'm going to insert two attachments to link the trail together.
So to do this I'm going to say *code on screen*
you need to add the char.Head after the name of the object as this tells the attachments where it will be placed then we are going to give it a name
drop a line and say *code on screen*
You could call your attachment anything, I'm calling mine TrailAttachment0 so that it makes sense when we're linking it up so we're going to do the same again. I'm just going to copy this line of code, going to drop a line and then paste it in again.
But I'm going to change the zeros (0) to ones (1)
so attachment0 will become attachment1
and trailattachment0 will become trailattachment1
and also we want it to be placed in the char.HumanoidRootPart
not the Head
So once we've done this, all that we need to do is change the attachment properties of the trail and then we will be ready to go.
So to do this we just need to say, *code on the screen now*
So that is our script completed so let's click the play button to test it
going to let my character load and there we go we have a trail which starts to follow us around when we run about in the game.
If you'd like more Roblox tutorials then please get in touch and request what you'd like to see. We'll get our team of Roblox Devs on the case!