Need help with Trail Gamepass

Hello, Dev Forum Users.

i need help with a few scripts to do with a Trail Gamepass. I have a trail gamepass - which is for sale. and im having a problem where it gives everybody who joins the trail.

Scripts -

RainbowTrailGamepass :

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,10660625)

    if  PlayerBoughtThisGamepass then
        trail.Enabled = true
        trail.Lifetime = 2
    end
end)

end)

RainbowTrail :

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local Rainbowtrail = game.ServerStorage.RainbowTrail:Clone()
Rainbowtrail.Parent = char.Head
local attachment0 = Instance.new(“Attachment”,char.Head)
attachment0.Name = “TrailAttachment0”
local attachment1 = Instance.new(“Attachment”,char.HumanoidRootPart)
attachment1.Name = “TrailAttachment1”
Rainbowtrail.Attachment0 = attachment0
Rainbowtrail.Attachment1 = attachment1
end)
end)

image

any help is appreciated.

3 Likes

Did you enable the RainbowTrail as default? (before you playtest or run the game in any way)

You could also change this part:

if  PlayerBoughtThisGamepass then
        trail.Enabled = true
        trail.Lifetime = 2
end

…to this:

trail.Enabled = PlayerBoughtThisGamepass
trail.Lifetime = 2

you can set the .Lifetime property no matter if the player owns the gamepass because it wouldn’t matter since the trail isn’t enabled anyways, right?

1 Like

hmmm. still didnt work, i had the trail enabled in its properties, should i have it disabled?
– i disabled it and it just removed it all together :frowning:

thanks for the reply

1 Like

The trail shouldn’t automatically delete itself if it’s not enabled, hm…

1 Like

I made a script myself to help you out and it works flawlessly.

All you’ll have to do is actually use MarketPlaceService and check if the player owns the gamepass - I set this to true for testing purposes.

local TrailReference = game.ReplicatedStorage.Trail

local TrailOffsetFromCenter = Vector3.new(1, 0, 0)

function GiveTrail(Trail, Parent)
	--||	Create and add attachments	
	local a0 = Instance.new("Attachment")
	a0.Position = TrailOffsetFromCenter
	a0.Parent = Parent
	
	local a1 = Instance.new("Attachment")
	a1.Position = -TrailOffsetFromCenter
	a1.Parent = Parent
	
	Trail.Attachment0 = a0
	Trail.Attachment1 = a1
	
	Trail.Enabled = true
	
	Trail.Parent = Parent
end

game.Players.PlayerAdded:Connect(function(Player)
	
	local PlayerOwnsGamePass = true
	
	Player.CharacterAdded:Connect(function(Character)
		if PlayerOwnsGamePass then
			local Trail = TrailReference:Clone()
			GiveTrail(Trail, Character:WaitForChild("HumanoidRootPart"))
		end
	end)
end)

I hope this helps. Have a great day!

1 Like

Should my script look like this or do i need to make some changes for it to work? - it didnt work but i know your script does, i am just not very good with scripting and i know im doing something wrong…

also should i have the trail enabled or disabled in its properties?

thanks so much for the help it means a lot.

local PlayerOwnsGamepass = MarketPlaceService:UserOwnsGamePassAsync(10660625)
       
        local TrailReference = game.ReplicatedStorage.Trail

local TrailOffsetFromCenter = Vector3.new(1, 0, 0)

function GiveTrail(Trail, Parent)
	--||	Create and add attachments	
	local a0 = Instance.new("Attachment")
	a0.Position = TrailOffsetFromCenter
	a0.Parent = Parent
	
	local a1 = Instance.new("Attachment")
	a1.Position = -TrailOffsetFromCenter
	a1.Parent = Parent
	
	Trail.Attachment0 = a0
	Trail.Attachment1 = a1
	
	Trail.Enabled = true
	
	Trail.Parent = Parent
end

game.Players.PlayerAdded:Connect(function(Player)
	
	local PlayerOwnsGamePass = true
	
	Player.CharacterAdded:Connect(function(Character)
		if PlayerOwnsGamePass then
			local Trail = TrailReference:Clone()
			GiveTrail(Trail, Character:WaitForChild("HumanoidRootPart"))
		end
	end)
end)
1 Like

As I said, you just need to change the PlayerOwnsGamePass variable which I already defined in the code. And I told you that the true boolean is just there for testing purposes so I don’t have to make a gamepass to test this out.

1 Like

do i disable this script -

local TrailReference = game.ReplicatedStorage.RainbowTrail

local TrailOffsetFromCenter = Vector3.new(1, 0, 0)

function GiveTrail(Trail, Parent)
	--||	Create and add attachments	
	local a0 = Instance.new("Attachment")
	a0.Position = TrailOffsetFromCenter
	a0.Parent = Parent
	
	local a1 = Instance.new("Attachment")
	a1.Position = -TrailOffsetFromCenter
	a1.Parent = Parent
	
	Trail.Attachment0 = a0
	Trail.Attachment1 = a1
	
	Trail.Enabled = true
	
	Trail.Parent = Parent
end

game.Players.PlayerAdded:Connect(function(Player)
	
	local MarketPlaceService = game:GetService("MarketplaceService")
	local UserId = Player.UserId
	local PlayerOwnsGamePass = MarketPlaceService.UserOwnsGamePassAsync(UserId, 10660625)
	
	Player.CharacterAdded:Connect(function(Character)
		if PlayerOwnsGamePass then
			local Trail = TrailReference:Clone()
			GiveTrail(Trail, Character:WaitForChild("HumanoidRootPart"))
		end
	end)
end)

is everything right on the trail too? - it is in the correct place

local TrailReference = game.ReplicatedStorage.Trail

Here, I’m referencing to the trail. You can change this to where your trail is located. And yes, you don’t need any other code than what I provided for you.

Let me clean this up for you. It looks like you’re confusing . and :, where : would be the proper way to fire a function.

local TrailReference = game.ReplicatedStorage.RainbowTrail
local TrailOffsetFromCenter = Vector3.new(1, 0, 0)
local MarketPlaceService = game:GetService("MarketplaceService")

function GiveTrail(Trail, Parent)
	--||	Create and add attachments	
	local a0 = Instance.new("Attachment")
	a0.Position = TrailOffsetFromCenter
	a0.Parent = Parent
	
	local a1 = Instance.new("Attachment")
	a1.Position = -TrailOffsetFromCenter
	a1.Parent = Parent
	
	Trail.Attachment0 = a0
	Trail.Attachment1 = a1
	
	Trail.Enabled = true
	
	Trail.Parent = Parent
end

game.Players.PlayerAdded:Connect(function(Player)
	local PlayerOwnsGamePass = MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 10660625)
	
	Player.CharacterAdded:Connect(function(Character)
		if PlayerOwnsGamePass then
			local Trail = TrailReference:Clone()
			GiveTrail(Trail, Character:WaitForChild("HumanoidRootPart"))
		end
	end)
end)

A structure that I like to have for my code which I think would be useful for you as well goes like this:

-- Variables

-- Functions

-- Connections

Example - let’s try and print a message when a player joins.

-- Variables
local Message = "has joined!" -- this would result in "PlayerName has joined!"

-- Functions
function PlayerAdded(Player)
	print(Player.Name, Message)
end

-- Connections
game.Players.PlayerAdded:Connect(PlayerAdded)
4 Likes

Thank you so much. Appreciate the help.