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

My tycoon shows the buyable button even though the item its depending on is not bought yet?

Asked by 1 year ago

I got a problem where you start a tycoon but from the literal start, it shows the button that still shouldnt be there.. the buttons are stairstwo button and one is walls button. i will show my main script where it all starts

-- Variables

local tycoonModel = script.Parent.Parent
local Items = {}

local boughtItems = tycoonModel:FindFirstChild("BoughtItems")
local buttons = tycoonModel:FindFirstChild("Buttons")
local dropperParts = tycoonModel:FindFirstChild("DropperParts")
local mainItems = tycoonModel:FindFirstChild("MainItems")
local Scripts = tycoonModel:FindFirstChild("Scripts")
local Values = tycoonModel:FindFirstChild("Values")

-- Tycoon Clone

local tycoonClone = tycoonModel:Clone()
tycoonClone.Parent = game.ReplicatedStorage

-- Owner Functions

mainItems.OwnerDoor.MainDoor.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and Values.OwnerValue.Value == nil then
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

        if Player:FindFirstChild("OwnsTycoon").Value == false then
            Values.OwnerValue.Value = Player
            Player:FindFirstChild("OwnsTycoon").Value = true

            while wait() do
                mainItems.OwnerDoor.MainDoor.SurfaceGui.TextLabel.Text = tostring(Values.OwnerValue.Value).." Tycoon"
            end
        end
    end
end)


-- Buying Functions

for i, v in pairs(buttons:GetChildren()) do
    local newItem = boughtItems:FindFirstChild(v.Item.Value)
    if newItem ~= nil then
        Items[newItem.Name] = newItem:Clone()
        newItem:Destroy()
    else
        v.ButtonPart.Transparency = 1
        v.ButtonPart.CanCollide = false
        v.ButtonPart.BillboardGui.Frame.Visible = false
    end

    if v:FindFirstChild("Dependency") then
        coroutine.resume(coroutine.create(function()
            v.ButtonPart.Transparency = 1
            v.ButtonPart.CanCollide = false
            v.ButtonPart.BillboardGui.Frame.Visible = false
            if boughtItems:WaitForChild(v.Dependency.Value, 100000) then
                v.ButtonPart.Transparency = 0
                v.ButtonPart.CanCollide = true
                v.ButtonPart.BillboardGui.Frame.Visible = true
            end
        end))
    end

    v.ButtonPart.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if Values.OwnerValue.Value == player then
                if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
                    if player:WaitForChild("leaderstats").Cash.Value >= v.Price.Value then
                        player.leaderstats.Cash.Value -= v.Price.Value
                        Items[v.Item.Value].Parent = boughtItems
                        v:Destroy()
                    end
                end
            end
        end
    end)
end

-- Cash Functions

local Debounce = false

mainItems.CashButton.ButtonPart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if Values.OwnerValue.Value == player then
            if Debounce == false then
                Debounce = true

                if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 108614806) then
                    player:WaitForChild("leaderstats").Cash.Value += Values.CashValue.Value * 2
                    wait()
                    Values.CashValue.Value = 0
                    wait(1)
                    Debounce = false
                else
                player:WaitForChild("leaderstats").Cash.Value += Values.CashValue.Value
                wait()
                Values.CashValue.Value = 0
                wait(1)
                    Debounce = false
                    end
            end
        end
    end
end)

while wait() do
    mainItems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = "$"..Values.CashValue.Value
end

Answer this question