Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
56 views6 pages

Print

The document provides code snippets to create a game pass donation system and shop in Roblox games. It shows how to check if a player owns a game pass, create UI elements like buttons and labels, and prompt players to purchase game passes or items using the MarketplaceService.

Uploaded by

kosmgaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views6 pages

Print

The document provides code snippets to create a game pass donation system and shop in Roblox games. It shows how to check if a player owns a game pass, create UI elements like buttons and labels, and prompt players to purchase game passes or items using the MarketplaceService.

Uploaded by

kosmgaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

print("Hello world!

")

-- Create a 'Game Pass' in the Roblox website for your game and note down its ID

local gamePassId = 123456789 -- replace with your game pass ID

game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(character)

if
game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,
gamePassId) then

-- If the player owns the game pass, give them some kind of bonus

print(player.Name .. " has donated!")

-- Add code here to provide benefits to the player

end

end)

end)

-- Create a ScreenGui in StarterGui

local screenGui = Instance.new("ScreenGui")

screenGui.Parent = game.StarterGui

-- Create a TextButton inside the ScreenGui

local textButton = Instance.new("TextButton")

textButton.Parent = screenGui

textButton.Position = UDim2.new(0, 10, 0, 10) -- Change this to position the button

textButton.Size = UDim2.new(0, 200, 0, 50) -- Change this to resize the button

textButton.Text = "Donate"

-- When the button is clicked, prompt the user to purchase your Game Pass

textButton.MouseButton1Click:Connect(function()
local gamePassId = 123456789 -- replace with your game pass ID

game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlaye
r, gamePassId)

end)

-- Create a ScreenGui in StarterGui

local screenGui = Instance.new("ScreenGui")

screenGui.Parent = game.StarterGui

-- Create a Frame inside the ScreenGui

local frame = Instance.new("Frame")

frame.Parent = screenGui

frame.Position = UDim2.new(0, 10, 0, 70) -- Change this to position the frame

frame.Size = UDim2.new(0, 200, 0, 300) -- Change this to resize the frame

-- Create a UIGridLayout inside the Frame to automatically position UI elements

local uiGridLayout = Instance.new("UIGridLayout")

uiGridLayout.Parent = frame

uiGridLayout.CellSize = UDim2.new(1, 0, 0, 50) -- Change this to resize the cells

-- Create a function to update the leaderboard

local function updateLeaderboard()

-- Clear the leaderboard

for _, child in ipairs(frame:GetChildren()) do

if child:IsA("TextLabel") then

child:Destroy()

end

end
-- Get the list of players

local players = game.Players:GetPlayers()

-- Sort the players by the number of donations (replace 'NumberOfDonations' with


the name of your leaderstat)

table.sort(players, function(a, b)

return (a.leaderstats.NumberOfDonations.Value >


b.leaderstats.NumberOfDonations.Value)

end)

-- Add each player to the leaderboard

for _, player in ipairs(players) do

local textLabel = Instance.new("TextLabel")

textLabel.Parent = frame

textLabel.Text = player.Name .. ": " ..


player.leaderstats.NumberOfDonations.Value -- replace 'NumberOfDonations' with the
name of your leaderstat

end

end

-- Update the leaderboard every 10 seconds

while wait(10) do

updateLeaderboard()

end

-- Create a ScreenGui in StarterGui

local screenGui = Instance.new("ScreenGui")

screenGui.Parent = game.StarterGui
-- Create a Frame inside the ScreenGui for the shop

local frame = Instance.new("Frame")

frame.Parent = screenGui

frame.Position = UDim2.new(0, 10, 0, 10) -- Change this to position the frame

frame.Size = UDim2.new(0, 200, 0, 300) -- Change this to resize the frame

-- Create a UIGridLayout inside the Frame to automatically position UI elements

local uiGridLayout = Instance.new("UIGridLayout")

uiGridLayout.Parent = frame

uiGridLayout.CellSize = UDim2.new(1, 0, 0, 50) -- Change this to resize the cells

-- Define your shop items

local shopItems = {

{name = "Item 1", price = 100}, -- replace with your item name and price

{name = "Item 2", price = 200}, -- replace with your item name and price

-- Add more items here

-- Add each item to the shop

for _, item in ipairs(shopItems) do

local textButton = Instance.new("TextButton")

textButton.Parent = frame

textButton.Text = item.name .. ": " .. item.price .. " Robux"

-- When the button is clicked, prompt the user to purchase the item

textButton.MouseButton1Click:Connect(function()
game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer,
item.productId)

end)

end

-- Create a ScreenGui in StarterGui

local screenGui = Instance.new("ScreenGui")

screenGui.Parent = game.StarterGui

-- Create a Frame inside the ScreenGui for the purchase GUI

local frame = Instance.new("Frame")

frame.Parent = screenGui

frame.Position = UDim2.new(0, 10, 0, 10) -- Change this to position the frame

frame.Size = UDim2.new(0, 200, 0, 100) -- Change this to resize the frame

-- Create a TextLabel inside the Frame for the item name

local textLabel = Instance.new("TextLabel")

textLabel.Parent = frame

textLabel.Position = UDim2.new(0, 10, 0, 10) -- Change this to position the text label

textLabel.Size = UDim2.new(0, 180, 0, 40) -- Change this to resize the text label

textLabel.Text = "Item Name" -- Replace with your item name

-- Create a TextButton inside the Frame for the purchase button

local textButton = Instance.new("TextButton")

textButton.Parent = frame

textButton.Position = UDim2.new(0, 10, 0, 60) -- Change this to position the button

textButton.Size = UDim2.new(0, 180, 0, 30) -- Change this to resize the button

textButton.Text = "Buy for X Robux" -- Replace X with your item price


-- When the button is clicked, prompt the user to purchase the item

textButton.MouseButton1Click:Connect(function()

local productId = 123456789 -- replace with your product ID

game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer,
productId)

end)

You might also like