Needing help with an Item description script for GUI(already done price, and name)

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to create a function when a button is clicked, you can see a
    description of each item. I’ve already done the name and price of each item.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is I need help with getting pointed towards the right direction. I would
    assume this would include some sort of table to iterate over each tool’s
    description, as I have a ‘string value’ in each tool, which is the description.

  3. What solutions have you tried so far? Did you look for solutions on the
    Developer Hub?
    I already tried looking through the Developer Hub, I know that there is information
    about tables and stuff, however I’m not much of a good scripter, and i thought the
    best place for help would be here.

    Ok, so basically I’ve been fallowing AlvinBlox’s tutorials on the sword fighting
    series, which have been really helpful. Now, what i’m planning to achieve is that
    once a player clicks the button to view a certain item, there should be a small
    description just below the price box, which obviously shows the description of that
    item.I noticed that throughout my server script called “Server Handler”, there is
    table that i would assume grabs the price of the item and the name of it, however
    if try to add another variable to it called “object.Description.Value”, which is a
    string value, after the other variables nothing happens, but if i add it before or in
    the middle of both these two variables it shows the description of the item. But the
    problem, is it interferes with the price table, and it shows up like “$cool sword”,
    which obviously is not what i wanted.I think i need to create a table for the string
    value, and then get that to show up in the ‘description textlabel’ I have.
    Anyways these are the scripts.and any help would be greatly appreciated. Also,
    this is my first post, so sorry for any careless mistakes or obvious solutions, i’m
    still learning :smiley:

— Server Script —

game.ReplicatedStorage:WaitForChild("GetTools").OnServerInvoke = function(player)
	local items = {}
	
 	for _, object in pairs(game.ServerStorage:WaitForChild("Items"):GetChildren()) do
		local itemProperties = {object.Name,object.Price.Value}
  	  	table.insert(items,itemProperties)
	end

	return items
end

game.ReplicatedStorage:WaitForChild("ItemCheck").OnServerInvoke = function(player,itemName)
if game.ServerStorage.PlayerData:FindFirstChild(player.Name).Inventory:FindFirstChild(itemName)	then
		return true
	else
		return false
	end
end

game.ReplicatedStorage:WaitForChild("PurchaseItem").OnServerInvoke = function(player,itemName)
	local coins = player.leaderstats.Coins
	local item = game.ServerStorage.Items:FindFirstChild(itemName)

	if item then
    	-- Item exists
		if game.ServerStorage.PlayerData[player.Name].Inventory:FindFirstChild(itemName) then
			if game.ServerStorage.PlayerData[player.Name].Equipped.Value ~= itemName then
				-- Currently unequipped
				game.ServerStorage.PlayerData[player.Name].Equipped.Value = itemName
				return "Equipped"		
			else
				game.ServerStorage.PlayerData[player.Name].Equipped.Value = ""
 				return "Unequipped"
			end
		end
	
		if coins.Value >= item.Price.Value then
			coins.Value = coins.Value - item.Price.Value
	
			local itemValue = Instance.new("ObjectValue")
			itemValue.Name = itemName
			itemValue.Parent = game.ServerStorage.PlayerData[player.Name].Inventory	
		
			return true	
		else
			
			return "NotEnoughCash"
		end		

		else
			return "NoItem"
	end

end

— Local Script in “Shop Gui” —

	local availableTools = 
    game.ReplicatedStorage:WaitForChild("GetTools"):InvokeServer()
	local mainFrame = script.Parent:WaitForChild("MainFrame")
	local safeArea = mainFrame:WaitForChild("SafeArea")
	local itemInformation = safeArea:WaitForChild("ItemInformation")
	local infoFrame = itemInformation.InfoFrame
	local selectedItem = itemInformation.SelectedItem
	local equippedItem = itemInformation.EquippedItem
	local numberOfItems = #availableTools
	
	local description = infoFrame.Description -- where my description textlabel is
	local itemFrame = safeArea.ItemFrame
	local shopButton = script.Parent:WaitForChild("ShopButton")
	local buyButton = infoFrame.BuyButton
	local equippedItemViewport = script.Parent:WaitForChild("EquippedItemViewport")
	local itemViewport = itemInformation.ItemViewport

 
	game.ReplicatedStorage.SendEquipped.OnClientEvent:Connect(function(equipped)	
		equippedItem.Value = equipped
		if equippedItem.Value ~= "" then
			local fakeCam = Instance.new("Camera")
			fakeCam.Parent = equippedItemViewport
			local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(equippedItem.Value.."Handle"):Clone()
			handle.Parent = equippedItemViewport
			equippedItemViewport.CurrentCamera = fakeCam
			fakeCam.CFrame = handle.CameraCFrame.Value
		
		end
	end)

	shopButton.MouseButton1Click:Connect(function()
	   	mainFrame.Visible = not mainFrame.Visible
	end)
	
	local PADDING_X = 0.02
	local DROPDOWN_Y = 0.2
	local DROPDOWN_X = 0.25
	
	local item1 = itemFrame:WaitForChild("Item1")
	
	local box
	local numRows = 1
	
	for i = 1,numberOfItems,1 do
		
		if i == 1 then
			box = item1
		else
	
			box = item1:Clone()
			box.Name = "Item"..i
			box.Parent = itemFrame
	
			if (i-1) / (5*numRows) == 1 then
				-- New row
				numRows = numRows + 1
				box.Position = UDim2.new(PADDING_X,0,box.Position.Y.Scale,0) + UDim2.new(0,0,DROPDOWN_Y*(numRows - 1))
			else
				-- Add to the X only
				box.Position = itemFrame["Item"..(i-1)].Position + UDim2.new(DROPDOWN_X,0,0,0)
			end
	
		end
	
		
		box.MouseButton1Click:Connect(function()
			for _, v in pairs(itemViewport:GetChildren())do
				if not v:IsA("Frame") then
					v:Destroy()
				end
			end
	
			local itemViewportCam = Instance.new("Camera")
			itemViewportCam.Parent = itemViewport
	
			local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
			handle.Parent = itemViewport	
	
			itemViewport.CurrentCamera = itemViewportCam
			itemViewportCam.CFrame = handle.CameraCFrame.Value 
	
			local owned = game.ReplicatedStorage.ItemCheck:InvokeServer(availableTools[i][1])
			
			if equippedItem.Value == availableTools[i][1] then
				infoFrame.Cash.Text = "Owned"
				infoFrame.BuyButton.Text = "Unequip"
			elseif owned == true then
				infoFrame.Cash.Text = "Owned"
				infoFrame.BuyButton.Text = "Equip"
			else
				infoFrame.BuyButton.Text = "Buy"
				infoFrame.Cash.Text = "$"..availableTools[i][2]
			end
		
			infoFrame.ItemName.Text = availableTools[i][1]
			selectedItem.Value = availableTools[i][1]
			
			for _, v in pairs(itemFrame:GetChildren()) do
				if v:IsA("ImageButton")	then
					v.BorderSizePixel = 0
				end
			end
		
			itemFrame["Item"..i].BorderSizePixel = 2
	
	end)
	
	local fakeCam = Instance.new("Camera")
	fakeCam.Parent = box.VPF
	local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1].."Handle"):Clone()
	handle.Parent = box.VPF
	box.VPF.CurrentCamera = fakeCam
	fakeCam.CFrame = handle.CameraCFrame.Value
	itemFrame["Item"..i].ItemName.Text = availableTools[i][1]
	
end -- Generating Boxes))

buyButton.MouseButton1Click:Connect(function()
	local result = game.ReplicatedStorage.PurchaseItem:InvokeServer(selectedItem.Value)
	if result == true then
		buyButton.BackgroundColor3 = Color3.fromRGB(42,149,42)
		buyButton.Text = "Bought!"
		wait(0.5)
		buyButton.Text = "Equip!"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	elseif result == "NotEnoughCash" then
		buyButton.BackgroundColor3 = Color3.fromRGB(204,31,31)
		buyButton.Text = "Not enough cash!"	
		wait(0.5)
		buyButton.Text = "Buy"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	elseif result == "Equipped" then
		equippedItem.Value = selectedItem.Value
		buyButton.BackgroundColor3 = Color3.fromRGB(42,149,42)
		buyButton.Text = "Equipped!"
		wait(0.5)
		buyButton.Text = "Unequip"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	elseif result == "Unequipped" then
		equippedItem.Value = ""
		buyButton.BackgroundColor3 = Color3.fromRGB(42,149,42)
		buyButton.Text = "Unequipped"
		wait(0.5)
		buyButton.Text = "Equip"
		buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
	end
end)


if equippedItem.Value ~= "" then
	local fakeCam = Instance.new("Camera")
	fakeCam.Parent = equippedItemViewport
	local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(equippedItem.Value.."Handle"):Clone()
	handle.Parent = equippedItemViewport
	equippedItemViewport.CurrentCamera = fakeCam
	fakeCam.CFrame = handle.CameraCFrame.Value
end

equippedItem:GetPropertyChangedSignal("Value"):Connect(function()
if equippedItem.Value ~= "" then

		for _, v in pairs(equippedItemViewport:GetChildren()) do
			if not v:IsA("Folder") then
				v:Destroy()
			end
		end
	
		local fakeCam = Instance.new("Camera")
		fakeCam.Parent = equippedItemViewport
		local handle = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(equippedItem.Value.."Handle"):Clone()
		handle.Parent = equippedItemViewport
		equippedItemViewport.CurrentCamera = fakeCam
		fakeCam.CFrame = handle.CameraCFrame.Value
	else
		for _, v in pairs(equippedItemViewport:GetChildren()) do
			if not v:IsA("Folder") then
				v:Destroy()
			end
		end
	end
end)	

also here are some screenshots —

Game - Roblox Studio 11_07_2020 3_59_18 PM_LI

Thanks in advance

Hey! Looks like ur just trying to add data onto a returned table. Not too hard of a problem.

So all the tools are in serverStorage, and a client isn’t able to see any userdata in serverStorage. So this script utilizes a remote function to get and return values describing the tools in an array. That part is here:

for _, object in pairs(game.ServerStorage:WaitForChild("Items"):GetChildren()) do
    local itemProperties = {object.Name,object.Price.Value}
    table.insert(items,itemProperties)
end

This is a 2D array, where information is stored like: `{{'Sword', 8}, {'Sword Gun', 80}, {'Super Sword', 800}, {'Super sword gun', 8000}}` To add in more information you'll want to add onto this line:
local itemProperties = {object.Name,object.Price.Value, object.Description.Value}

Now that was only server-sided. You'll want to also edit the client-side so that it does something with the 3rd element in the tool arrays. The best place for that might be here:
infoFrame.ItemName.Text = availableTools[i][1]
selectedItem.Value = availableTools[i][1]
infoFrame.Description.Text = availableTools[i][3] -- New line

availableTools is the data you’re getting back from server about your tools. It will loop every tool, availableTools[i] gets the array of the tool info it’s iterating over. availableTools[i][3] would get the third element in that array, which from the edit in the server script is going to be the description.

Hope this solves the problem you had. Sorry if I over-explained at all.

1 Like

Thanks so much, my respect is eternally given to you :smile:

Haha thanks! Keep on scripting dude, you’ll pick up some cool tricks.