Trying to connect 2 diffrent GUI Function?

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!!

Hello, what line appears to be the issue? Add some print statements around, and follow standard debugging procedures to see what the issue is for us to help you. You provided a windows media video, not a standard video format, so it isn’t playable on all devices. You also weren’t very descriptive of what the issue is.

I understand, the line that seems causing the issue is the UpdateItems Function, I just can’t make the word (“Equipped”) in the Ui of the bottom of the screen be the same as the word from the right side of the screen.

Here is the issue screen :

Here is the correct scenario of what it should be :

As you can see the difference is the correct scenario have both the bottom Ui and the right Ui saying the same word.

I tried my best o explain the problem to you but sadly im not really good at typing english formaly, I hope you understand.

What is the name of the button at the bottom, and where do you set the text? Add a print statement that prints what you will be setting the text to when you are changing it.

image
here is the list of names

If you did what I send in the first message, you could probably figure it out pretty quickly. It takes time to learn how to debug your code, but it is an essential skill. Looking at your code, you probably just need to update the status variable every time you access it.

It works, thx!! yes it does need a status variable on the tempUsage.Activated function thx

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.