When I test my button, if it sees I own a certain asset it is supposed to teleport me somewhere. And even though I already own the gamepass specified in the script, it still prompts the purchase and doesn't teleport.
local gamepassID = 2657409 local assetID = 870836117 local debounce = false local function OwnsShades(Hit) if debounce == false then debounce = true local plr = game.Players:GetPlayerFromCharacter(Hit.Parent) if plr then if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,assetID) then print(plr.Name .. " owns the Midnight Shades") plr.MoveTo(workspace.Grass.Position) else print(plr.Name .. " doesn't own the shades") game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamepassID) end wait(1) debounce = false end end end script.Parent.Touched:Connect(OwnsShades)
For gamepasses, you have to use UserOwnsGamePassAsync rather than PlayerOwnsAsset (which is only for items & clothing). So, for example:
local gamepassID = 2657409 local assetID = 870836117 local debounce = false local function OwnsShades(Hit) if debounce == false then debounce = true local plr = game.Players:GetPlayerFromCharacter(Hit.Parent) if plr then if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, gamepassID) then print(plr.Name .. " owns the gamepass") plr.MoveTo(workspace.Grass.Position) else print(plr.Name .. " doesn't own the gamepass") game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamepassID) end end wait(1) debounce = false end end script.Parent.Touched:Connect(OwnsShades)
You also needed to move the debounce outside the if plr then
statement, otherwise if the object that hit was not a player, it would never be set back to false again. Also keep in mind UserOwnsGamePassAsync
takes the player's UserId, rather than the player itself. You may also need to add a PromptPurchaseFinished for immediate feedback after the player has purchased the gamepass.