Trail for a specific person

i have added a trails to my game with script it works for everyone but how can i change that script which will make one trail for a specific person
“game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local trail = game.ServerStorage.Trail:Clone()
trail.Parent = char.Head
local attachment0 = Instance.new(“Attachment”, char.Head)
attachment0.Name = “TrailAttachment0”
local attachment1 = Instance.new(“Attachment”, char.HumanoidRootPart)
attachment1.Name = “TrailAttachment1”
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
end)
end)”

You can just check if their UserId is equal to the provided userid that you gave the script like this:

game.Players.PlayerAdded:Connect(function(player)
if player.UserId == "put userid here" then
player.CharacterAdded:Connect(function(char)
local trail = game.ServerStorage.Trail:Clone()
trail.Parent = char.Head
local attachment0 = Instance.new(“Attachment”, char.Head)
attachment0.Name = “TrailAttachment0”
local attachment1 = Instance.new(“Attachment”, char.HumanoidRootPart)
attachment1.Name = “TrailAttachment1”
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
end
end)
end)

Then if they join the game and their UserId is equal to the one that you gave in the script they will be automatically given the trail, the reason we use UserId is because their name can change but UserIds can’t change.

You can have tables on who can have the trail.

local Allowed = {1825185} -- random numbers as an example, but the number must be the player's user ID

game:GetService("Players").PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Char)
        if table.find(Allowed,Player.UserId) then
        --other codes
        end)
    end)
end)

Please note this is not the only way.

He said that he wanted it to be only for a specific person and not a list of people so tables are highly unnecessary here because tables aren’t made to only store one thing, that’s not their purpose, if you want to store one thing then you can simply store that thing in a variable.

By doing this you will also make it unnecessary complicated for him to understand while the solution is simple, look at my method above for an example of that.

Both of you guys method didnt work , maybe i did it wrong because i m not really a scripter, i am just a modeler if u can help me u can come to team create

Can you show us your new script?

sorry but i cant because i already undo everything related to those script…

The problem here couldve been because its a string, try this

if player.UserId == 123 then --replace 123 to the specific persons UserId

this also didnt work , how can i send image here?

Capture

Maybe you need to move the if player.UserId == 1159802652 then after the CharacterAdded?
This will also make it you respawn with the trail again.

Edit: Also, please do not use the 2nd argument of Instance.new. It is not suggestable.

try adding a WaitForChild on both the head and humanoidrootpart

i am literally confused what u guys are trying to say lol becasue i am not a scripter so i was trying to get help with this script , i will just say clearly now : i have added a trail which is blue color for evryone so i want my trail to be different from others …

Your topic says “Trail for specific person” and not “different color from others”.

Well, back to your script. This will require some lot tweaking in the script for it to be different colors from others, how do you want it to be changed? (Random, specific users, etc)

specific user , like the owner {me} should have like different colors then other maybe like rainbow

Do you have a seperate trail in serverstorage? What part of the script does not work? Is it the part where the trail does not show up, or is it where the trail is not a different color? If it is the latter, you will have to create a trail with a different color.

local Players = game:GetService("Players");
local ServerStorage = game:GetService("ServerStorage");

local Player = Players.PlayerAdded:Wait();
local Character = Player.CharacterAdded:Wait()

local ID = --// your target user id goes here

if Player.UserId == ID then
   local Trail = ServerStorage:WaitForChild("Trail")
   local Attachment0 = Instance.new("Attachment")
   Attachment0.Parent = Character.Head

   local Attachment1 = Instance.new("Attachment")
   Attachment0.Parent = Character.HumanoidRootPart

   trail.Attachment0 = Attachment0
   trail.Attachment1 = Attachment1
end

The only reason I didn’t use the second optional argument in the Instance.new constructor is because if this is firing regularly (assuming your servers are 100 players in size) then it can get really slow. Reference.

1 Like