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

How do I fix my upgrade system?

Asked by 5 years ago

I'm trying to make a upgrade system in my game that let's me upgrade the power of a weapon, but I don't seem to know what I'm doing. Help please.

local Players = game.Players
local Player = Players.LocalPlayer
local Character = Player.Character
local Items = {}
local Buttons = {}

function Search(location)
    for i,v in pairs(location:GetChildren()) do
        if v:IsA("Tool") then
            table.insert(Items, v)
        end
    end
end

function Refresh()
    for i,v in pairs(Buttons) do
        v:Destroy()
    end
    for i,v in pairs(Items) do
        local Button = script.Template:Clone()
        Button.Name = v.Name
        Button.Image = v.TextureId
        Button.LayoutOrder = i
        Button.Parent = script.Parent.ScrollingFrame
        table.insert(Buttons, Button)
        Button.MouseButton1Click:connect(function()
            if script.Parent.Selected.Value == nil or script.Parent.Selected.Value ~= v then
                script.Parent.Info.ItemName.Text = v.Name
                script.Parent.Info.ItemImage.Image = v.TextureId
                script.Parent.Info.UpgradeCost.Text = Button.UpgradeCost.Value
                script.Parent.Selected.Value = v
                if script.Parent.Selected.Value ~= script.Parent.Upgrading.Value then
                    script.Parent.Location.Value = v.Parent
                    script.Parent.Info.Upgrade.Label.Text = "Upgrade"
                    script.Parent.Info.Upgrade.ImageColor3 = Color3.fromRGB(0,255,0)
                    game.SoundService.ClickTwo:Play()
            elseif
               script.Parent.Selected.Value == script.Parent.Upgrading.Value then
                    script.Parent.Location.Value = v.Parent
                    script.Parent.Info.Upgrade.Label.Text = "Nothing Selected"
                    game.SoundService.ClickTwo:Play()
                    end
            end
        end)
    end
end

function BackpackRefresh()
    Items = {}
    Search(Character)
    Search(Player.Backpack)
    Refresh()
end

BackpackRefresh()
Player.Backpack.ChildAdded:Connect(BackpackRefresh)
Player.Backpack.ChildRemoved:Connect(BackpackRefresh)

Character.ChildAdded:Connect(BackpackRefresh)
Character.ChildRemoved:Connect(BackpackRefresh)

Answer this question