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

My tycoon script is slightly broken and I need help with adding dependency?

Asked by 4 years ago
Edited 4 years ago

So I am making a tycoon from scratch as a coding practice but there are 2 main issues I am running into at the moment:

1) Although one of the buttons are Transparent and CanCollide is false, you can still walk over the button and buy the item

and 2) I cannot for the life of me figure out how I'd implement dependency, I have tried many things for it but it never seems to work, I do have a stringValue in the buttons for the dependency but I just can't figure it out

if someone could explain how I would do the second one and if anyone knows why the first is happening? I'll leave my script below

local Buttons = script.Parent.Buttons:GetChildren()
local Purchases = script.Parent.Purchases
local Essentials = script.Parent.Essentials

for i,v in pairs(Buttons) do
    local debounce = false
    local timer = 10
    v.Head.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            if hit.Parent.Name == Essentials.OwnerDoor.Owner.Value then
                local player = game.Players:FindFirstChild(hit.Parent.Name)
                if player.leaderstats.Cash.Value >= v.Price.Value then
                    if not debounce then 
                        debounce = true

                        local ItemModel = Purchases:FindFirstChild(v.Item.Value)
                        local ItemParts = ItemModel.Parts
                        local Item = ItemParts:GetChildren()
                        for i,v in pairs(Item) do
                            v.CanCollide = true
                            v.Transparency = 0
                        end

                        v.Head.Transparency = 1
                        v.Head.CanCollide = false

                        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - v.Price.Value

                        wait(timer)
                        debounce = false
                    end
                end
            end
        end
    end)
end

Answer this question