I know that the button is located at the NPC's head and its dialog and its shop (ScreenGui) and its frame that has button that i need to close after a player has bought the gamepass. Here is the script.
local passid = 1422734652 -- The ID of the gamepass goes here
local GamePassService = game:GetService('GamePassService')
local PlayerName = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local ButtonToBeClose = PlayerName.Shop3.Frame:WaitForChild("GamepassPurchase")
local player = game:GetService("Players").LocalPlayer
if GamePassService:PlayerHasPass(player, passid) then
ButtonToBeClose.Visible = false
end
