Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How come the it still buys the thing when i dont have enough?

Asked by 4 years ago

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)

0
put all of your code in a code block JesseSong 3916 — 4y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

This should work

cost = 500 -- the price you want

cost.Value = cost.Value - money.Value
Ad

Answer this question