Problem with Gamepass Script

It wont change the value in the player

local MarketPlaceService = game:GetService(“MarketplaceService”)

local id = 22088092

game.Players.PlayerAdded:Connect(function(Player)
if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, id) then
local maxHatsv = Player:FindFirstChild(“maxHats”)
maxHatsv.Value = maxHatsv.Value + 4
end
end)

Can anybody help with this?

UserOwnsGamePassAsync(userId, gamepassId) takes two arguments, it’s correct.

1 Like

There are 2 possibles issues here that I would see. Firstly, they may not own the pass, invalidating the if statement. To check this use an else statement and some debug prints. I assume this is not the case, though.

The second issue is that when referencing maxHats, it doesn’t find anything and as such returns nil. This makes the value nil and as such cannot be added to. Instead of a FindFirstChild, attempt WaitForChild as that way it’ll wait until it exists, because you may be referencing it before it exists.

1 Like

I’ve tried WaitForChild it doesn’t seem to work though

(Nope nevermind it worked! thank you)