I’m trying to make the UI on the Bottom side of the screen that indicates the items is eqquipped or not, correspondent towards the right side of the screen.
Here is the video recording of the bug
I tried rearranging the script and watching youtube tutorials but doesn’t work
local replicatedStorage = game:GetService("ReplicatedStorage")
local shopModule = require(replicatedStorage:WaitForChild("ShopModule"))
local getDataFunc = replicatedStorage:WaitForChild("GetData")
local interactItemFunc = replicatedStorage:WaitForChild("InteractItem")
local Player = game.Players.LocalPlayer
local gui = script.Parent
local exit = gui.ShopFrame.PagesFrame.ReturnFrame.TextButton
local coins = gui.ShopFrame.Coins
local limit = gui.ShopFrame.TowersEquipped
local itemsFrame = gui.ShopFrame.ListSelection.Container
local statsFrame = gui.ShopFrame.StatsFrame
local playerData = {}
local function GetItemStatus(itemName)
if table.find(playerData.SelectedTowers, itemName) then
return "Equipped"
elseif table.find(playerData.OwnedTowers, itemName) then
return "Owned"
else
return "For Sale"
end
end
local function InteractItem(itemName)
local data = interactItemFunc:InvokeServer(itemName)
if data then
playerData = data
UpdateItems()
end
end
function UpdateItems(itemName)
coins.Text = playerData.Coins
limit.Text = #playerData.SelectedTowers.."/5"
for i, tower in pairs(shopModule) do
-- Find Old Button --
local oldBtn = itemsFrame:FindFirstChild(tower.Name)
if oldBtn then
oldBtn:Destroy()
end
-- Creating New Button --
local newButton = itemsFrame.Template:Clone()
local model = replicatedStorage.Towers:FindFirstChild(tower.Name):Clone()
local camera = Instance.new("Camera")
newButton.Name = tower.Name
newButton.TowerName.Text = tower.Name
newButton.PriceLabel.Text = tower.Price
newButton.Visible = true
newButton.Parent = itemsFrame
model.Parent = newButton.Viewport.WorldModel
model.Humanoid.Animator:LoadAnimation(model.AnimsFolder.Idle):Play()
camera.Parent = newButton.Viewport
camera.CFrame = CFrame.new(model.HumanoidRootPart.Position + Vector3.new(-3,0,-7.5), model.HumanoidRootPart.Position)
newButton.Viewport.CurrentCamera = camera
local status = GetItemStatus(tower.Name)
if status == "For Sale" then
newButton.PriceLabel.Text = tower.Price
elseif status == "Equipped" then
newButton.PriceLabel.Text = "Equipped"
newButton.PriceLabel.TextColor3 = Color3.new(0.666667, 0.333333, 1)
newButton.PriceLabel.Size = UDim2.new(1, 0,0.18, 0)
elseif status == "Owned" then
newButton.PriceLabel.Text = "Owned"
newButton.PriceLabel.TextColor3 = Color3.new(0.333333, 0.666667, 1)
newButton.PriceLabel.Size = UDim2.new(1, 0,0.18, 0)
end
newButton.Activated:Connect(function()
local oldModel = workspace.ShopSection.TowerModels:FindFirstChild(tower.Name)
if oldModel then
gui.ShopFrame.InteractUsages:FindFirstChild(oldModel.Name):Destroy()
oldModel:Destroy()
end
for i, v in pairs(workspace.ShopSection.TowerModels:GetChildren()) do
gui.ShopFrame.InteractUsages:FindFirstChild(v.Name):Destroy()
v:Destroy()
end
statsFrame.Visible = true
statsFrame.TowerName.TextLabel.Text = tower.Name
statsFrame.Description.Text = tower.Description
local WpModel = replicatedStorage.Towers:FindFirstChild(tower.Name):Clone()
WpModel.Parent = workspace.ShopSection:WaitForChild("TowerModels")
WpModel.HumanoidRootPart.CFrame = CFrame.new(workspace.ShopSection.CharacterPlatform.Position + Vector3.new(0, WpModel.Humanoid.HipHeight + (WpModel.PrimaryPart.Size.Y / 2) + WpModel["Left Leg"].Size.Y, 0))
WpModel.Humanoid.Animator:LoadAnimation(WpModel.AnimsFolder.Idle):Play()
local tempUsage = gui.ShopFrame.TemplateUsage:Clone()
tempUsage.Parent = gui.ShopFrame.InteractUsages
tempUsage.Visible = true
tempUsage.Name = tower.Name
for i, v in pairs(statsFrame.StatsGrid:GetChildren()) do
if v.Name == "Price" then
statsFrame.StatsGrid[v.Name].Visible = true
statsFrame.StatsGrid[v.Name].TextLabel.Text = WpModel.Config.Price.Value
elseif WpModel.Config.AttackStats:FindFirstChild(v.Name) then
statsFrame.StatsGrid[v.Name].Visible = true
statsFrame.StatsGrid[v.Name].TextLabel.Text = WpModel.Config.AttackStats:FindFirstChild(v.Name).Value
elseif v:IsA("Frame") then
statsFrame.StatsGrid[v.Name].Visible = false
end
end
if status == "For Sale" then
tempUsage.Text = "$"..tower.Price
tempUsage.BackgroundColor3 = Color3.new(1, 1, 0.498039)
elseif status == "Equipped" then
tempUsage.BackgroundColor3 = Color3.new(0.666667, 0.333333, 1)
tempUsage.Text = "Equipped"
elseif status == "Owned" then
tempUsage.BackgroundColor3 = Color3.new(0.333333, 0.666667, 1)
tempUsage.Text = "Owned"
end
tempUsage.Activated:Connect(function()
InteractItem(tower.Name)
end)
end)
end
end
Thanks for helping!!