Hello!
I’m attempting to make an upgrade system in a tower defense game where the gui will showcase what the next tower upgrade stats are. However I’m having trouble accessing the value and displaying it in the ui and I don’t know how to go about doing it.
This is the idea I have in mind
The upgraded stats are held in the upgraded towers model in a value which is inside a configuration.
Once Upgraded, the tower is replaced with the next level version according to the upgrade value. What I want to do is get the values of the upgraded towers values but I don’t know how to go about doing it.
Script That Changes UI
local function toggleTowerInfo()
workspace.Camera:ClearAllChildren()
gui.Towers.Title.Text = "Towers: " .. placedTowers .. "/" .. maxTowers
if selectedTower then
CreateRangeCircle(selectedTower)
gui.DarkGrayInterior.Visible = true
local config = selectedTower.Config
selectedTower.PrimaryPart.CFrame, selectedTower)
gui.DarkGrayInterior.CurrentStats.Stats.Damage.Value.Text = config.Damage.Value
gui.DarkGrayInterior.CurrentStats.Stats.Range.Value.Text = config.Range.Value
gui.DarkGrayInterior.CurrentStats.Stats.Cooldown.Value.Text = config.Cooldown.Value
gui.DarkGrayInterior.Selection.Title.TowerName.Text = selectedTower.Name
gui.DarkGrayInterior.Selection.Title.TowerImage.Image = config.Image.Texture
gui.DarkGrayInterior.Selection.Title.OwnerName.Text = config.Owner.Value .. "'s"
local modes = {
["First"] = "rgb(150, 150, 150)",
["Last"] = "rgb(50, 50, 50)",
["Near"] = "rgb(50, 150, 0)",
["Strong"] = "rgb(200, 50, 50)",
["Weak"] = "rgb(50, 100, 200)"
}
local color = modes[config.TargetMode.Value]
gui.DarkGrayInterior.Selection.Action.Target.Title.Text = "Target: <font color=\"" .. color .. "\">" .. config.TargetMode.Value .. "</font>"
if config.Owner.Value == Players.LocalPlayer.Name then
gui.DarkGrayInterior.Selection.Action.Visible = true
local upgradeTower = config:FindFirstChild("Upgrade")
if upgradeTower then
gui.DarkGrayInterior.Selection.Outline.Upgrade.Visible = true
gui.DarkGrayInterior.Selection.LightGrayOutline.Price.Text = "Upgrade (" .. upgradeTower.Value.Config.Price.Value .. ")"
else
gui.DarkGrayInterior.Selection.Outline.Upgrade.Visible = false
end
else
gui.DarkGrayInterior.Selection.Action.Visible = false
end
else
gui.DarkGrayInterior.Visible = false
end
end
Script That Allows For Upgrades
gui.DarkGrayInterior.Selection.Outline.Upgrade.Activated:Connect(function()
if selectedTower then
local upgradeTower = selectedTower.Config.Upgrade.Value -- upgrade tower = level 2
local upgradeSuccess = spawnTowerFunction:InvokeServer(upgradeTower.Name, selectedTower.PrimaryPart.CFrame, selectedTower)
if upgradeSuccess then
selectedTower = upgradeSuccess
toggleTowerInfo()
end
end
end)
This is how the ui is organized
Any help is appreciated!