How do i make the Player get the Gamepass instantly?

im kind of new to scripting so please dont judge, i’ve tried alot of solutions on this forum but non of them worked, whenever the prompt finished, doesnt matter if the player bought it or not he still gets the 2x speed.

script.Parent.MouseButton1Click:Connect(function(plr)
	local MarketplaceService = game:GetService("MarketplaceService")
	local Players = game:GetService("Players")
	local player = game.Players.LocalPlayer
	local char = player.Character
	local productID = 26100589
	MarketplaceService:PromptGamePassPurchase(player, productID)
	if MarketplaceService.PromptGamePassPurchaseFinished then
			local Humanoid = char:FindFirstChild("Humanoid")
			Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed * 2

	end
end)

This only checks if the prompt is finished not whether or not they completed the purchase

Ohhh okay. but still, how do i make it work tho?

This is an event, not a Boolean value.
https://developer.roblox.com/en-us/api-reference/event/MarketplaceService/PromptGamePassPurchaseFinished

yea i kind of figured it out myself but i forgot what i replaced it with cuz i found that specific line from a solution here. and i still cant find a solution that will fix it

1 Like

Put this in a server script, so you can handle all your gamepasses in one placed.

local MPS = game:GetService("MarketplaceService")
MPS.PromptGamePassPurchaseFinished:Connect(function(player, gamepassID, purchased)
	if purchased then
		if gamepassID == 0000000 then
			--code
		end		
	end
end)
3 Likes

Thank You all! really helped me

1 Like
script.Parent.MouseButton1Click:Connect(function()
    local MPS = game:GetService("MarketplaceService")
    local Player = game.Players.LocalPlayer
    local Character = Player.Character
    local ProductID = 26100589

    MPS:PromptGamePassPurchase(Player.UserId, ProductID)

    local function purchaseFinished()
            local Humanoid = Character:FindFirstChild("Humanoid")
        Humanoid.WalkSpeed = 32
    end

    MPS.PromptGamePassPurchaseFinished:Connect(function(player, gamePassId, wasPurchased)
        if wasPurchased == true and gamePassId == ProductID then
            purchaseFinished()
        end
    end
end)

Let me know any problems you have!