BLOXBUILDS
Discord
Back
TYCOON

Auto-Collect Gamepass

Paste into ServerScriptService as a Script. Replace GAMEPASS_ID. Players who own the pass pick up nearby CashDrop parts without touching the collector.

-- Paste into ServerScriptService as a Script.
-- Replace GAMEPASS_ID with your game pass id. 0 disables collection.

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

local GAMEPASS_ID = 0
local RANGE = 18

local owns: { [Player]: boolean } = {}

local function getCash(player: Player): IntValue
	local leaderstats = player:FindFirstChild("leaderstats")
	if not leaderstats then
		leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player
	end
	local cash = leaderstats:FindFirstChild("Cash")
	if not cash then
		cash = Instance.new("IntValue")
		cash.Name = "Cash"
		cash.Value = 0
		cash.Parent = leaderstats
	end
	return cash :: IntValue
end

local function refresh(player: Player)
	if GAMEPASS_ID == 0 then
		owns[player] = false
		return
	end
	local ok, result = pcall(function()
		return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAMEPASS_ID)
	end)
	owns[player] = ok and result == true
end

Players.PlayerAdded:Connect(refresh)
for _, player in ipairs(Players:GetPlayers()) do
	refresh(player)
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamePassId, wasPurchased)
	if wasPurchased and gamePassId == GAMEPASS_ID then
		owns[player] = true
	end
end)

task.spawn(function()
	while true do
		for _, player in ipairs(Players:GetPlayers()) do
			if owns[player] then
				local root = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
				if root then
					for _, inst in ipairs(workspace:GetChildren()) do
						if inst:IsA("BasePart") and inst.Name == "CashDrop" and (inst.Position - root.Position).Magnitude <= RANGE then
							local value = inst:GetAttribute("Value")
							local amount = if typeof(value) == "number" then value else 10
							getCash(player).Value += amount
							inst:Destroy()
						end
					end
				end
			end
		end
		task.wait(1)
	end
end)