My script when a person already owns the gamepass does not run

This script is meant to manage the Noob Skin gamepass, and make it so that if you own the skin, the overlay that prevents you from using the skin without purchasing it gets deleted.

But, When I run my script, it doesn’t do anything, even if the player owns the product, and no errors are given.

I have no idea what causes this.

(This is a local script)

local LocalPlayer = game.Players.LocalPlayer
local NoobEvent = game.ReplicatedStorage.RemoveNoobPurchase
local MarketPlaceService = game:GetService("MarketplaceService")
local NoobPassID = 10695409
local PurchaseNoobButton = LocalPlayer:WaitForChild("PlayerGui").ChooseSkin.Frame.ScrollingFrame.Noob.TextButton
local LoadedIn = game:GetService("ReplicatedStorage"):WaitForChild("LoadedIn")

LoadedIn.Changed:Connect(function(player)
	local success, message = pcall(function()
			OwnsNoob = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, NoobPassID)
	end)
	
		if OwnsNoob == true then
			print("This dude owns the noob")
		
			PurchaseNoobButton:Destroy()		
		end
	end)

local function OnNoobPurchased(Player, purchasedPassID, purchaseSuccess)
	if purchaseSuccess == true and purchasedPassID == NoobPassID then
		print("This dude bought the noob")
		
		PurchaseNoobButton:Destroy()
	end
end

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(OnNoobPurchased)

Here is the part that has the main issue:

LoadedIn.Changed:Connect(function(player)
	local success, message = pcall(function()
			OwnsNoob = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, NoobPassID)
	end)
	
		if OwnsNoob == true then
			print("This dude owns the noob")
		
			PurchaseNoobButton:Destroy()	
		end
	end)

If you need more info, feel free to ask!

i dont think you need == true there?

1 Like

I tried it without, and it worked the same?

Maybe try doing it without the pcall function and just try checking for it straight ahead? (without the local)

if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, NoobPassID) then
  print("This dude owns the noob")
  PurchaseNoobButton:Destroy()	
end
1 Like

i’ll try that, brb. (30 Chars)

hmm, worked the same. i should mention this is in a local script, as it handles gui

Then what error do you get? on what line?

1 Like

Players.IdontPlayz343.PlayerGui.LocalScript:23: Expected ‘end’ (to close ‘function’ at line 8), got ; did you forget to close ‘then’ at line 16?

you’re probably missing an end somewhere.

1 Like

Can you verify that the .Changed event for LoadedIn fires?

To do this, add a breakpoint or a print on the inside of the .Changed event.

1 Like

Can you verify that the .Changed event for LoadedIn fires?

To do this, add a breakpoint or a print on the inside of the .Changed event.
it printed,
and here is an error Players.IdontPlayz343.PlayerGui.LocalScript:10: attempt to index boolean with ‘UserId’

You tried to use the value passed with the .Changed event as the player, try using your LocalPlayer variable instead. The reason this is a boolean is because the value that changed with the .Changed is a boolean value.

1 Like

How would i use my LocalPlayer variable in this instance?

Change that to

OwnsNoob = MarketPlaceService:UserOwnsGamePassAsync(LocalPlayer.UserId, NoobPassID)
1 Like

It worked! thank you both! =D
(30 chars)