If The Player Has Bought The Game Pass, He Has A Trail, I'm Trying to figure out how to do it but it's not working, what am i doing wrong?

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = ????
 
function onPlayerSpawned(player) 
    
    local hasPass = false
 

    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
  print("Has Game Pass for Gun")
    end)
   
    
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end
 
    if hasPass == true then

local Trail = game.ServerStorage["Trail"]
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local plrTrail = Trail:Clone()
		plrTrail.Parent = char.HumanoidRootPart
		if char:FindFirstChild("UpperTorso") then
			plrTrail.Attachment0 = char.Head.FaceFrontAttachment
			plrTrail.Attachment1 = char.Torso.RootRigAttachment
		else
			plrTrail.Attachment0 = char.Head.FaceFrontAttachment
			plrTrail.Attachment1 = char.Torso.WaistBackAttachment
		end
	end)
	local character = script.Parent.Parent.Parent
end)
 end
end 

game.Players.PlayerAdded:connect(function(player)
  player.CharacterAdded:connect(function()
    onPlayerSpawned(player)
  end)
end)


Players.PlayerSpawned:Connect(onPlayerSpawned)

11 comments

0

I don't think you set the gamepassID to the ID

0

Did you even code this? (Lines 4, 48 and 49)

0

Yes, That Doesn't Matter, But What Is Wrong With Other Parts?

0

If you really did code this, you'd know that that's because of line 25; it waits for when a player joins the game, in other words, it wont add the trail until another player joins.

0

So, How Can I Fix That?

0

...Remove line 25?

0

I Removed, It Gives Me This Error: ServerScriptService.TrailGive:26: attempt to index global 'plr' (a nil value)

0

Of course, you didn't define plr at all. If you'd've used Script Analysis, you'd know that. :/ Oh well. You already have the player defined as player in your script; why not use that?

0

Still, It Doesn't Work Sir, Can You Write A Script Please

0

No, I will not. It's quite evident you didn't write this script. :/ Please come back when you've at least tried to make an attempt.

0

I'm Trying, But I Can't Figure It Out, That's Why I Came Here so You Guys Can Help me