Enabling a trail for a user

Hello, I am a beginner scripter needing help with scripting trails.

Here is what I have so far:
StarterPlayer > StarterCharacterScripts > Trail > ParticleEmitter+ Script
image

The Script:

Before I had only the following in my script, and it allowed all users to have the trail

However now I would like for only specific users to have the trail, and I am unsure on how to do this. I tried following a few other topics similar to mine, however the way they had their trails were different from mine. A little help to achieve this would be greatly appreciated! :grin:

1 Like

Parts are not supposed to go inside StarterCharacterScripts – at least, I don’t think so.

1 Like

What I would suggest is move the trail to the player’s humanoid root part.

2 Likes

Where can I find the player’s humanoid root part? :sweat_smile:

1 Like

Have a table storing all the userids for players that should have the trail. Then use table.find() to check if a player has the userId when they join, then give them the trail. I would also suggest that instead of a while loop to constantly move the emitter, just use a weldconstraint on it. Which is cleaner and reduces unnecessary script activity as well

1 Like

Have you even read the code? Try reading line 5

1 Like
local allowedUsers = {
84398600
}

local character = script.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(character)

if table.find(allowedUsers,player.UserId) then
    while wait(1) do
        script.Parent.CFrame = script.Parent.Parent.HumanoidRootPart.CFrame
    end
end

try this

1 Like

I’m going to change how you do this

local allowedUsers = {
84398600,
552028399,
1234567890,
SomeOtherUserIds, --Remember to separate each of them with a comma
}

local character = script.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(character)

if table.find(allowedUsers,player.UserId) then
    script.Parent.ParticleEmitter.Parent = character:WaitForChild("HumanoidRootPart") --Much smoother and less laggy than doing it over and over again every second
end
1 Like

I’m trying to add another person’s ID to the table, and I put it like this

local allowedUsers = {
84398600, 84694314
}

However when myself and the other player join we both don’t get the trail. So I was wondering if I added the second value properly.

Nevermind that, I figured I needed to put the second ID on a new line :sweat_smile:

There is no need to put them on the second line, but it looks better, and is easier to find mistakes. It is likely another problem, so you should give us any output errors that we need to fix.

It also might be some stupid mis-spelling that I accidentally made, which happens a lot when I’m not typing in studio, so any output errors would be useful.
Also, this script should be in a script, and not a local script, otherwise it will only appear for the client.

1 Like

I’ve checked the logs and there is no error related to my trails. I’ve tried testing with me and my friend, changing who gets the trail and who doesn’t and it seems to work fine. Thank you for your help!