i have a code and i need to know why it works when i don't have enough money
local tycoon = script.Parent.Parent.Parent local tycoonOwner = tycoon.TycoonOwner local button = script.Parent local container = button.Parent local purchasedItem = container.PurchasedItem local cost = container.Cost.Value
local itemClone = purchasedItem:Clone() purchasedItem:Destroy()
local function getPlayerFromPart(part) local character = part.Parent
if character then local player = game.Players:GetPlayerFromCharacter(character) itemClone.Parent = container return player end
end local function attemptToBuy(player) local money = player.leaderstats.Funds
if money.Value >= cost then money.Value = money.Value - cost itemClone.Parent = container button:Destroy() end
end local function onTouched(otherPart) local player = getPlayerFromPart(otherPart) if player then if tycoonOwner.Value then attemptToBuy(player) end end end
button.Touched:Connect(onTouched)
This should work
cost = 500 -- the price you want cost.Value = cost.Value - money.Value