Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Gamepass localscript works somewhat for some reason?!?!

--variables
local marketplaceservice = game:GetService("MarketplaceService") 
local Luigi = game.Lighting.StarterCharacter
local player = game.Players.LocalPlayer
local gamepass = 9693560

script.Parent.MouseButton1Click:Connect(function() --starts all this up when they click
	marketplaceservice:PromptGamePassPurchase(player, gamepass) --sends them the purchase
	if marketplaceservice:UserOwnsGamePassAsync(player.userId, gamepass) then --sees if they have it
		game.StarterPlayer.StarterCharacter:Destroy() --destroys the normal startercharacter
		Luigi.Parent = game.StarterPlayer --adds the new startercharacter
	end
end)

My problem is when I press it, and I buy the test purchase, it does nothing after. Or even if I click it again. There is no output errors. For context it is a localscript in a text button. I won't be online to elaborate or answer questions as it is 10 PM for me right now.

1 answer

Use the PromptGamePassPurchaseFinished event. It tells you the player's response to the prompt.

--variables
local marketplaceservice = game:GetService("MarketplaceService") 
local Luigi = game.Lighting.StarterCharacter
local player = game.Players.LocalPlayer
local gamepass = 9693560

script.Parent.MouseButton1Click:Connect(function() --starts all this up when they click
	marketplaceservice:PromptGamePassPurchase(player, gamepass) --sends them the purchase
	marketplaceservice.PromptGamePassPurchaseFinished:Connect(function(player, gamepass, wasPurchased) -- wasPurchased is for whether or not the player purchased the game pass
		if wasPurchased == true then 
        		game.StarterPlayer.StarterCharacter:Destroy() --destroys the normal startercharacter
        		Luigi.Parent = game.StarterPlayer --adds the new startercharacter
		else
			print("Did not buy gamepass!")
		end
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.