How to Create Tool Gamepass on Click - Roblox Studio Tutorial

Published: 21 September 2024
on channel: fil1pex
222
9

--serverscriptservice
local gamepassID = your id here
local toolName = "Taser"

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")


local function hasGamePass(player)
local success, result = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassID)
end)
if success then
return result
else
warn("Couldn't find gamepass for player:", player.Name)
return false
end
end


local function giveTool(player)
if not player.Backpack:FindFirstChild(toolName) and ReplicatedStorage:FindFirstChild(toolName) then
local tool = ReplicatedStorage:FindFirstChild(toolName):Clone()
tool.Parent = player.Backpack
end
end


Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function()
if hasGamePass(player) then
giveTool(player)
end
end)
end)


MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasedGamepassID, purchaseSuccess)
if purchaseSuccess and purchasedGamepassID == gamepassID then
giveTool(player)
end
end)

--
--local script in textbutton
local gamePassID = 926767265


local function promptPurchase()
local player = game.Players.LocalPlayer
game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamePassID)
end


script.Parent.MouseButton1Click:Connect(promptPurchase)


Watch video How to Create Tool Gamepass on Click - Roblox Studio Tutorial online without registration, duration hours minute second in high quality. This video was added by user fil1pex 21 September 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 222 once and liked it 9 people.