Text doesn't update in shop system

Hi, I am making a shop system, and I need help with fixing the text not updating when owning an item in a folder that is not in the "Tools" folder.

Here’s my script:

local toolsFolder = game.ReplicatedStorage:WaitForChild("Tools")
local coinsFolder = game.ReplicatedStorage:WaitForChild("Coins")
local gamepassFolder = game.ReplicatedStorage:WaitForChild("Gamepass")

local conf = game.ReplicatedStorage:WaitForChild("Configuration")
local currencyName = conf:WaitForChild("CurrencyName")
local canBuyMultipleTimes = conf:WaitForChild("CanBuyItemMultipleTimes")

local rsModules = game.ReplicatedStorage:WaitForChild("ModuleScripts")
local GetTools = require(rsModules:WaitForChild("GetTools"))

local localScript = script.Parent.Parent

local frame = localScript.Parent.ShopFrame
local selectedFrame = frame:WaitForChild("SelectedTool")

local currentlySelectedTool = nil

local Functions = {}

-- Function to check if a tool is in any specified shop folders
local function IsToolInShopFolders(tool)
	return toolsFolder:FindFirstChild(tool.Name) or coinsFolder:FindFirstChild(tool.Name) or gamepassFolder:FindFirstChild(tool.Name)
end

function IsToolEquipped(plr, toolName)
	for _, tool in pairs(plr.Backpack:GetChildren()) do
		if tool:IsA("Tool") and tool.Name == toolName then
			print("Tool found in Backpack: " .. toolName)
			return true
		end
	end
	for _, tool in pairs(plr.Character:GetChildren()) do
		if tool:IsA("Tool") and tool.Name == toolName then
			print("Tool found in Character: " .. toolName)
			return true
		end
	end
	print("Tool not equipped: " .. toolName)
	return false
end

function Functions.SelectTool(tool: Tool, updateSelectedTool: boolean)
	print("Selecting tool: " .. tool.Name)
	if currentlySelectedTool ~= tool or updateSelectedTool == true then
		currentlySelectedTool = tool

		local toolImage = tool.TextureId
		local toolName = tool.Name
		local toolDesc = tool.Configuration:FindFirstChild("Description") and tool.Configuration.Description.Value or ""
		local toolPrice = tool.Configuration.Price.Value

		selectedFrame.ToolImage.Image = toolImage
		selectedFrame.ToolName.Text = toolName
		selectedFrame.ToolDescription.Text = toolDesc

		local plrTools = GetTools(game.Players.LocalPlayer)
		print("Player tools: " .. table.concat(plrTools, ", "))

		if table.find(plrTools, toolName) then
			if IsToolEquipped(game.Players.LocalPlayer, toolName) then
				selectedFrame.BuyButton.TextLabel.Text = "[EQUIPPED]"
				selectedFrame.BuyButton.ImageColor3 = Color3.fromRGB(255, 255, 255)
				print("Tool is equipped: " .. toolName)
			else
				selectedFrame.BuyButton.TextLabel.Text = "[EQUIP]"
				selectedFrame.BuyButton.ImageColor3 = Color3.fromRGB(143, 143, 143)
				print("Tool is not equipped but owned: " .. toolName)
			end
		else
			selectedFrame.BuyButton.TextLabel.Text = "$" .. toolPrice
			print("Tool price set: $" .. toolPrice)

			if game.Players.LocalPlayer.leaderstats[currencyName.Value].Value < toolPrice then
				selectedFrame.BuyButton.ImageColor3 = Color3.fromRGB(143, 143, 143)
				print("Not enough currency to buy tool: " .. toolName)
			else
				selectedFrame.BuyButton.ImageColor3 = Color3.fromRGB(255, 255, 255)
				print("Enough currency to buy tool: " .. toolName)
			end
		end

		selectedFrame.Visible = true
		print("Selected frame updated and made visible for tool: " .. toolName)
	end
end

function Functions.GetSelectedTool()
	return currentlySelectedTool
end

return Functions

Here’s some pictures to see what I mean:
image
image

I think the issue is with IsToolEquipped()
IsToolEquipped returns true if the tool is in backpack but also returns true if it’s equiped, it only returns false if the tool isn’t found at all. Which is lkely why your else “[EQUIP]” isn’t popping, IsToolEquipped will be true.

1 Like

an improved version of your script with added debugging and ensuring the GetTools function checks all folders:

local toolsFolder = game.ReplicatedStorage:WaitForChild("Tools")
local coinsFolder = game.ReplicatedStorage:WaitForChild("Coins")
local gamepassFolder = game.ReplicatedStorage:WaitForChild("Gamepass")

local conf = game.ReplicatedStorage:WaitForChild("Configuration")
local currencyName = conf:WaitForChild("CurrencyName")
local canBuyMultipleTimes = conf:WaitForChild("CanBuyItemMultipleTimes")

local rsModules = game.ReplicatedStorage:WaitForChild("ModuleScripts")
local GetTools = require(rsModules:WaitForChild("GetTools"))

local localScript = script.Parent.Parent

local frame = localScript.Parent.ShopFrame
local selectedFrame = frame:WaitForChild("SelectedTool")

local currentlySelectedTool = nil

local Functions = {}

-- Function to check if a tool is in any specified shop folders
local function IsToolInShopFolders(tool)
	return toolsFolder:FindFirstChild(tool.Name) or coinsFolder:FindFirstChild(tool.Name) or gamepassFolder:FindFirstChild(tool.Name)
end

function IsToolEquipped(plr, toolName)
	for _, tool in pairs(plr.Backpack:GetChildren()) do
		if tool:IsA("Tool") and tool.Name == toolName then
			print("Tool found in Backpack: " .. toolName)
			return true
		end
	end
	for _, tool in pairs(plr.Character:GetChildren()) do
		if tool:IsA("Tool") and tool.Name == toolName then
			print("Tool found in Character: " .. toolName)
			return true
		end
	end
	print("Tool not equipped: " .. toolName)
	return false
end

function Functions.SelectTool(tool: Tool, updateSelectedTool: boolean)
	print("Selecting tool: " .. tool.Name)
	if currentlySelectedTool ~= tool or updateSelectedTool == true then
		currentlySelectedTool = tool

		local toolImage = tool.TextureId
		local toolName = tool.Name
		local toolDesc = tool.Configuration:FindFirstChild("Description") and tool.Configuration.Description.Value or ""
		local toolPrice = tool.Configuration.Price.Value

		selectedFrame.ToolImage.Image = toolImage
		selectedFrame.ToolName.Text = toolName
		selectedFrame.ToolDescription.Text = toolDesc

		local plrTools = GetTools(game.Players.LocalPlayer)
		print("Player tools: " .. table.concat(plrTools, ", "))

		if table.find(plrTools, toolName) then
			if IsToolEquipped(game.Players.LocalPlayer, toolName) then
				selectedFrame.BuyButton.TextLabel.Text = "[EQUIPPED]"
				selectedFrame.BuyButton.ImageColor3 = Color3.fromRGB(255, 255, 255)
				print("Tool is equipped: " .. toolName)
			else
				selectedFrame.BuyButton.TextLabel.Text = "[EQUIP]"
				selectedFrame.BuyButton.ImageColor3 = Color3.fromRGB(143, 143, 143)
				print("Tool is not equipped but owned: " .. toolName)
			end
		else
			selectedFrame.BuyButton.TextLabel.Text = "$" .. toolPrice
			print("Tool price set: $" .. toolPrice)

			if game.Players.LocalPlayer.leaderstats[currencyName.Value].Value < toolPrice then
				selectedFrame.BuyButton.ImageColor3 = Color3.fromRGB(143, 143, 143)
				print("Not enough currency to buy tool: " .. toolName)
			else
				selectedFrame.BuyButton.ImageColor3 = Color3.fromRGB(255, 255, 255)
				print("Enough currency to buy tool: " .. toolName)
			end
		end

		selectedFrame.Visible = true
		print("Selected frame updated and made visible for tool: " .. toolName)
	end
end

function Functions.GetSelectedTool()
	return currentlySelectedTool
end

return Functions

Check your GetTools function in the rsModules script is handling tools from all specified folders.

1 Like

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