Im trying to make a gamepass that makes it when a player buys it they wear a hat when they join the game but i cant get around his problem i tried fixing the script but i think i just made it worse since im a beginner at scripting.
local MarketPlaceService = game:GetService('MarketplaceService')
local GamepassId = 11001479
game.Players.PlayerAdded:Connect(function(PlayerWhoJoined)
PlayerWhoJoined.CharacterAdded:Connect(function()
if MarketPlaceService:UserOwnsGamePassAsync(PlayerWhoJoined.UserId, GamepassId) then
local BetaHat = script:FindFirstChild('Accessory'):Clone()
BetaHat.Parent = PlayerWhoJoined.Character
end
end)
MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(Player,GamePassId,Purchased)
if GamePassId == GamepassId and Purchased == true then
local BetaHat = script:FindFirstChild('Accessory'):Clone()
BetaHat.Parent = PlayerWhoJoined.Character
end
end)
end)

3 comments
This script looks good to me ! Are there any errors or warning pertaining to your code?
Make it print something if they have the game pass , and see if it prints anything.
idk it gives me this error - ServerScriptService.HatGamepass:7: attempt to index nil with 'Clone'