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

Why is my Tycoon Kit build model button not working? {SOLVED}

Asked by 9 years ago

I was so stupid, I had 0 instead of false on line 17

model = script.Parent.Parent.Parent.Model -- Filepath of model to be built
purchasePrice = 150 -- How much money this costs to purchase
moneyIncrease = 0 -- How much MORE money they earn after purchase
moneyInterval = 0 -- How much SHORTER the interval is between income after purchase
buildMethod = "Appear" --[[
    Appear:
        Parts appear at the same time in their original position
    Fade:
        Parts fade (1 by 1) from completely transparent to their original transparency.
    Fall:
        Parts fall (1 by 1) from the sky to their original position.
--]]
-------------------------------------------------------------------------------------------------
modelBackup = model:Clone()
modelName = modelBackup.Name
model:remove()
db = false -- I had 0 here :l
parts = {}

function checkForParts(v)
    if v:IsA("BasePart") then
        table.insert(parts,v)
    else
        checkForParts(v)
    end
end

script.Parent.Touched:connect(function(hit)
    if db == false then
        db = true
        if game.Players:FindFirstChild(hit.Parent.Name) ~= nil and hit.Parent.Name == script.Parent.Parent.Parent.OwnerName.Value then
            stats = game.Players:FindFirstChild(hit.Parent.Name):FindFirstChild("leaderstats")
            if stats ~= nil then
                money = stats:FindFirstChild(game.Workspace.Leaderboard.MoneyName.Value)
                if money.Value >= purchasePrice then
                    money.Value = money.Value-purchasePrice
                    script.Parent.Parent.Parent.MoneyIncrease.Value = script.Parent.Parent.Parent.MoneyIncrease.Value+moneyIncrease
                    script.Parent.Parent.Parent.MoneyInterval.Value = script.Parent.Parent.Parent.MoneyInterval.Value-moneyInterval
                    modelBackup.Parent = script.Parent.Parent.Parent
                    script.Parent.Parent.Name = "Building..."
                    if modelBackup:IsA("BasePart") then
                        table.insert(parts,modelBackup)
                        for i,v in pairs(modelBackup:GetChildren()) do
                            checkForParts(v)
                        end
                        model = parts[modelBackup]
                    else
                        for i,v in pairs(modelBackup:GetChildren()) do
                            checkForParts(v)
                        end
                        model = Instance.new("Model",script.Parent.Parent.Parent)
                        model.Name = modelName
                    end
                    if buildMethod ~= "Appear" and buildMethod ~= "Fade" and buildMethod ~= "Fall" then
                        buildMethod = "Appear"
                    end
                    if buildMethod == "Appear" then
                        for i = 1,#parts do
                            parts[i].Parent = model
                        end
                    elseif buildMethod == "Fade" then
                        for i = 1,#parts do
                            transparency = parts[i].Transparency
                            parts[i].Parent = model
                            repeat
                                parts[i].Transparency = parts[i].Transparency-0.05
                                wait()
                            until parts[i].Transparency >= transparency-0.05 and parts[i].Transparency <= transparency+0.05
                            parts[i].Transparency = transparency
                        end
                    elseif buildMethod == "Fall" then
                        for i = 1,#parts do
                            parts[i].Parent = model
                        end
                    end
                    script.Parent.Parent:remove()
                else
                    oldName = script.Parent.Parent.Name
                    script.Parent.Parent.Name = "You need "..purchasePrice-money.Value.." more "..game.Workspace.Leaderboard.MoneyName.Value.." to buy this!"
                    wait(3)
                    script.Parent.Parent.Name = oldName
                end
            end
        end
        db = false
    end
end)

Answer this question