How to Create Tool Gamepass on Click - Roblox Studio Tutorial

Опубликовано: 21 Сентябрь 2024
на канале: 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)