Can't store more than one Item

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

When I select the Item GUI, I want it to store the item from the player’s inventory. And when there is an item in the GUI slot, I want to send the item back into the player’s inventory.

  1. What is the issue? Include screenshots / videos if possible!

    (Items in Storage)

    (Clicked katana2 item, no item in backpack)

    (Clicked katana3 item, item in backpack)

Currently, I can only retrieve the first item located in the “itemTools” folder in my ServerStorage. For example, If I click my GUI to retrieve my “katana2” item, the item doesn’t go into the player’s inventory.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I believe the issue lies within “GetChildren” and the if statement. Since the if statement only seems to read the first item then, it stops if the name isn’t correct. I believe I just need a better way to cycle through all the names of the children of the folder.

serverStoragePNG

codeIssuePng

Currently, I need to know which is the best way of cycling through my folder without stopping at the first string!

1 Like

Could you show a bit more of your code?
If you put the three " ``` " symbols before and after your code here in the forums, it will format it as text.

What more do you need specifically?
Local script:

local player = game:GetService("Players").LocalPlayer.Character
local UIS  = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")

local RE = replicatedStorage:WaitForChild("storeItemRE")

local Gui = script.Parent



for _, Object in pairs(Gui:GetDescendants()) do
	if Object:IsA("Frame") then
		Object.InputBegan:Connect(function(input, gameProcessed)
			if input.UserInputType == Enum.UserInputType.MouseButton1 then
				print(Object.Name)
				
				local toolLess = false
				
				local toolObject = player:FindFirstChildOfClass("Tool")
				
				
				RE:FireServer(Object:FindFirstChildOfClass("TextBox"), toolObject) 
				
			end
				
		
		end)
	end
end
ServerScript: 
local replicatedStorage = game:GetService("ReplicatedStorage")

local RE = replicatedStorage:WaitForChild("storeItemRE")

local SS = game:GetService("ServerStorage")

local itemStorage = SS:WaitForChild("itemTools")



RE.OnServerEvent:Connect(function(player, gui, tool)
   
   if tool == nil then
   	
   	print("No Item in Hand")
   	
   	if gui.Text == "None" then

   		print("Empty")


   		return 

   	end


   	if gui.Text ~= "None" then

   		print("Full Storage")
   		

   		for _, toolTag in pairs(itemStorage:GetChildren()) do
   			
   			print(toolTag)

   			if toolTag.Name == gui.Text then

   				local clone = toolTag:Clone()
   				
   				print(clone.Name)

   				clone.Parent = player.Backpack

   				print(toolTag.Name)
   				
   				

   			end

   			gui.Text = "None"

   		end
   		
   		return

   	end
   	
   	
   	
   end
   
   
   
   
   if tool then
   	
   	if gui.Text == "None" then

   		print("Empty")

   		gui.Text = tool.Name

   		tool:Destroy()

   		return 

   	end


   	if gui.Text ~= "None" then

   		print("Full Storage")


   		for _, toolTag in pairs(itemStorage:GetChildren()) do
   			
   			print("testPrint")

   			if gui.Text == toolTag.Name then

   				local clone = toolTag:Clone()

   				print(clone.Name)

   				clone.Parent = player.Backpack


   			end

   			gui.Text = "None"

   		end

   		return

   	end
   end
   
   
   
   
end)




You cannot input the TextBot argument because if the text is changed on the client, the server cannot access the text from the client and therefore it won’t update properly.

Some fixes for this are making it send the text instead of the textbox, or updating the text on the server.

This might not be the issue, but check if it is.

1 Like

I’ll be sure to try it! I’ll experiment.

I’ve tried creating a variable on the server, but it didn’t seem to fix the issue. I think the issue lies within the “for loop” since it only clones the first item listed in the “itemTools” folder.