local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local BuyItemEvent = ReplicatedStorage.Events:WaitForChild("BuyItems")
local Tools = ServerStorage:WaitForChild("Tools")
local Players = game:GetService("Players")
local prices = {["Speed Coil"] = 1500000}
local gamePasses = {["Invisibility Cloak"] = 1405857530} -- id
local function GiveTool(player, ItemName)
local Item = Tools:FindFirstChild(ItemName)
if not Item then print("item not found") return end
if player.Backpack:FindFirstChild(Item.Name) or (player.Character and player.Character:FindFirstChild(Item.Name)) then
return
end
Item:Clone().Parent = player.Backpack
end
BuyItemEvent.OnServerEvent:Connect(function(player, itemName)
print(player.Name, itemName, gamePasses[itemName])
if gamePasses[itemName] then
local success, owns = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePasses[itemName])
end)
if success and owns then
print(player.Name .. " owns GamePass for " .. itemName .. ", granting item.")
GiveTool(player, itemName)
else
warn("Purchase failed or player doesn't own GamePass:", itemName)
end
return
end
local price = prices[itemName]
if not price then return end
local leaderstats = player:FindFirstChild("leaderstats")
local Money = leaderstats:WaitForChild("Money")
local Item = Tools:FindFirstChild(itemName)
** You are now Level 1! **