#tycoon script

2 messages · Page 1 of 1 (latest)

charred orbit
#
local lemonadestand = ScrollingFrame.LemonadeStand
local lsAmount = 20
local perspawn = 2
local dollar
local lsHasManager = false
local lsPurchaseManager = script.Parent.Parent:WaitForChild("ManagerShop").ScrollingFrame.Frame.LSManager.TextButton
lsPurchaseManager.MouseButton1Click:Connect(function()
    if plr.leaderstats.Cash.Value >= 200 then
        lsHasManager = true
        plr.leaderstats.Cash.Value -= 200
        lsPurchaseManager.Text = "You already own this."
        lsPurchaseManager.Active = false
    else
        StarterGui:SetCore("SendNotification", {
            Title = "Insufficient funds.",
            Text = "You don't have enough cash to purchase this item."
        })
    end
    lsHasManager = true 
end)
if lsHasManager == false then
    lemonadestand.TextButton.MouseButton1Click:Connect(function()
        dollar = workspace.LemonadeStandSpawner:Clone()
        dollar.Parent = workspace
        dollar.Position = workspace.LemonadeStandSpawner.Position - Vector3.new(0,1,0)
        dollar.Anchored = false
        dollar.CanCollide = true
    end)
elseif lsHasManager == true then
    task.spawn(function()
        while task.wait(1) do
            dollar = workspace.LemonadeStandSpawner:Clone()
            dollar.Parent = workspace
            dollar.Position = workspace.LemonadeStandSpawner.Position - Vector3.new(0,1,0)
            dollar.Anchored = false
            dollar.CanCollide = true
        end
    end)
end```
when a player clicks on `lsPurchaseManager` and they have sufficient funds, i want the code in the `task.spawn(function()` to work, but it doesn't. how do i fix this
hushed cargo
#
local lemonadestand = ScrollingFrame.LemonadeStand
local lsAmount = 20
local perspawn = 2
local dollar
local lsHasManager = false
local lsPurchaseManager = script.Parent.Parent:WaitForChild("ManagerShop").ScrollingFrame.Frame.LSManager.TextButton

lsPurchaseManager.MouseButton1Click:Connect(function()
    if plr.leaderstats.Cash.Value >= 200 then
        lsHasManager = true
        plr.leaderstats.Cash.Value -= 200
        lsPurchaseManager.Text = "You already own this."
        lsPurchaseManager.Active = false
    else
        StarterGui:SetCore("SendNotification", {
            Title = "Insufficient funds.",
            Text = "You don't have enough cash to purchase this item."
        })
    end
    lsHasManager = true 
end)
if lsHasManager == false then
    lemonadestand.TextButton.MouseButton1Click:Connect(function()
        dollar = workspace.LemonadeStandSpawner:Clone()
        dollar.Parent = workspace
        dollar.Position = workspace.LemonadeStandSpawner.Position - Vector3.new(0,1,0)
        dollar.Anchored = false
        dollar.CanCollide = true
    end)
end
-- NEW vvv
task.spawn(function()
    while task.wait(1) do
        if lsHasManager then
            dollar = workspace.LemonadeStandSpawner:Clone()
            dollar.Parent = workspace
            dollar.Position = workspace.LemonadeStandSpawner.Position - Vector3.new(0,1,0)
            dollar.Anchored = false
            dollar.CanCollide = true
        end
    end
end)