How do I make a gamepass script also work for a certain person?

Hello!!
I am a very new scripter so sorry if this seems dumb.
I have coded a script that when a person with a gamepass joins they get a rainbow trail, but I would also want it to work for certain people. Here is my code just for the gamepass:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		wait(2)
		local trail = char.Head.Trail
		local MarketPlaceService = game:GetService("MarketplaceService")
		local UserId = player.UserId
		local PlayerBoughtThisGamepass = MarketPlaceService:UserOwnsGamePassAsync(UserId, 13387455)

		if PlayerBoughtThisGamepass then
			trail.Enabled = true
			trail.Lifetime = 5
		else
			trail.Enabled = false
		end
	end)
end)

Thanks!!

1 Like

You can use:

if player.Name == "playerNameHere" then
-- do stuff
end
1 Like

So if you want someone specific you would need to check if their UserId is the ID of the specific person then give them the trail let me, you might think checking the name is better but it is not because they could change their name but not their ID so here is the code:

if player.UserID == then -- Players ID
	-- Trail
end

Put that inside of your function, to get the user’s ID go to their Roblox profile and take the numbers from the link and paste that between the “==” and “then” If you want I can get it for you just link me their profile. Hope this helps!

1 Like
game.Players.PlayerAdded:Connect(function(player)
    if player.UserId == whatevertheplayersidis then
        -- Trail code
    end
	player.CharacterAdded:Connect(function(char)
		wait(2)
		local trail = char.Head.Trail
		local MarketPlaceService = game:GetService("MarketplaceService")
		local UserId = player.UserId
		local PlayerBoughtThisGamepass = MarketPlaceService:UserOwnsGamePassAsync(UserId, 13387455)

		if PlayerBoughtThisGamepass then
			trail.Enabled = true
			trail.Lifetime = 5
		else
			trail.Enabled = false
		end
	end)
end)

I made the code for you.

And here is where you can find their user ID:


It is underlined in red at the top.

1 Like

If you are going to have more than a couple of ‘special’ players, you might want to make a list and then just look up the userid in that list. A good example of how to use this is from the API entry for table:

local t = {"a", "b", "c", "d", "e"}
print(table.find(t, "d")) --> 4
print(table.find(t, "z")) --> nil, because z is not in the table
print(table.find(t, "b", 3)) --> nil, because b appears before index 3

so then you’d have your list of user ID’s defined say: special = {12345, 54321, 11111}
then in your if statement you could add OR table.find(special, UserId)
I’m not sure if UserId is a string or an int so you might need quotes in the fake userids in my example.

1 Like