No errors coming up when ran. The hat goes into the script as a child. Hat is an accessory with handle named 'Accessory'.
local MarketplaceService = game:GetService('MarketplaceService') local GAMEPASSID = 5885163 local function AddHatToCharacter(Character) script:FindFirstChildOfClass('Accessory'):Clone().Parent = Character end MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, GamePassId, Purchased) if Purchased then if GamePassId == GAMEPASSID then Player.CharacterAdded:Connect(function(Character) AddHatToCharacter(Character) end) if Player.Character then AddHatToCharacter(Player.Character) end end end end) game:GetService('Players').PlayerAdded:Connect(function(Player) if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GAMEPASSID) then Player.CharacterAdded:Connect(function(Character) AddHatToCharacter(Character) end) end end)
First of all you can try putting the accessory inside of ReplicatedStorage and then clone it into the player from there if they have the gamepass:
local Accessory = game:GetService("ReplicatedStorage"):FindFirstChildOfClass("Accessory") local Market = game:GetService("MarketplaceService") local GPId = 5885163 local function AddAccessory(Char) local clone = Accessory:Clone() clone.Parent = Char end local function Gamepass_Purchased(Player, PassId, IfPurchased) if IfPurchased == true then if PassId == GPId then if Player.Character ~= nil then AddAccessory(Player.Character) end Player.CharacterAdded:Connect(function(Char) AddAccessory(Char) end) end end end local function CheckPass(Player, PassId) if Market:UserOwnsGamePassAsync(Player.UserId, PassId) then repeat wait() until Player.Character ~= nil if Player.Character ~= nil then AddAccessory(Player.Character) end Player.CharacterAdded:Connect(function(Char) AddAccessory(Char) end) end end Market.PromtGamePassPurchaseFinished:Connect(Gamepass_Purchased) game.Players.PlayerAdded:Connect(CheckPass)
This should work for you