TYCOON
Cash Collector
Paste as a Script inside the collector part. CashDrop blocks that touch it are converted into Cash. A player touch also adds a small amount. Upgrade and rebirth multipliers are included.
-- Paste as a Script inside the collector part.
local Players = game:GetService("Players")
local TOUCH_VALUE = 25
local part = script.Parent
if not part or not part:IsA("BasePart") then
return
end
local lastTouch: { [Player]: number } = {}
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 multiplier(player: Player): number
local upgrade = player:GetAttribute("UpgradeLevel") or 0
local rebirths = player:GetAttribute("Rebirths") or 0
return (1 + upgrade * 0.25) * (1 + rebirths)
end
local function pay(player: Player, amount: number)
getCash(player).Value += math.floor(amount * multiplier(player))
end
part.Touched:Connect(function(hit)
if hit.Name == "CashDrop" and hit:IsA("BasePart") then
local value = hit:GetAttribute("Value")
local amount = if typeof(value) == "number" then value else 10
local closest: Player? = nil
local closestDistance = 40
for _, player in ipairs(Players:GetPlayers()) do
local root = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
if root then
local distance = (root.Position - part.Position).Magnitude
if distance < closestDistance then
closest = player
closestDistance = distance
end
end
end
if closest then
pay(closest, amount)
end
hit:Destroy()
return
end
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player then
return
end
if lastTouch[player] and os.clock() - lastTouch[player] < 0.4 then
return
end
lastTouch[player] = os.clock()
pay(player, TOUCH_VALUE)
end)