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)
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)
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.
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)