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

Member of "Players" that represents all of the players in the server?

    plr = game.Players. -- Missing

local button = script.Parent

local marketplaceService = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:Connect(function()

MarketplaceService:PromptGamePassPurchase(plr, 6255391)

end)

So this is the script I used to create a ScreenGui TextButton that offers a gamepass, but I'm a noob, so I need the member of "Players" that represents all of the players in the server. If someone could please tell me what that would be, I would greatly appreciate it, thanks!

1 answer

✓ Accepted answer

What you did wrong is that Players is a service, and so it doesn't do anything. Since you're prompting the service a gamepass purchase it won't work since it has to be a player. What I'm assuming here is that this is a LocalScript located inside of a TextButton/ImageButton. So we're going to modify it to fit our needs.

local Player = game:GetService("Players").LocalPlayer
local MarketplaceService = game:GetService("MarketplaceService")
local Button = script.Parent

local function onClicked()
	MarketplaceService:PromptGamePassPurchase(Player,6255391)
end

Button.MouseButton1Click:Connect(onClicked)

In the code what we're doing is that we get the Player, MarketPlaceService, and the Button. Every time the button is clicked it prompts the player the gamepass.

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