How do i sent an item to chest based on what are the currently item name the event has fired?

I did some random math and item table on the local script when the player open the chest. Then i make the event fired the “Item Name” to the sever and then on the sever i make some variable for the Items Folder like:

local Items = game.SeverStorage.Items:GetChildren()
giveItemsEvent.OnSeverEvent:Connect(function(player, chosenItem)

then i need to get the weapon so i can place that item inside the chest that the player just open but the problem is when i did

local choosenItem= Items[chosenItem]:Clone()	

it give me “attempt to index nil with ‘Clone’” error.
What’s Happen?

the error is saying such an item does not exist,
try printing Item[ChosenItem]
if you get nil , then it means the item you asked for does not exist.

--also do if conditions so these errors don't break the game like
if Item[chosenItem] then
   local chosenItem =  Item[chosenItem]:Clone()
else
    print(Item[chosenItem])

yea its printing nil. The event is firing out (“Sword”) and there’s (“Sword”) Inside the Items folder

can i see the chunk of code where youre firing the event?

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and canPress == true then
		canPress = false
		local randNum = math.random(1,maxPercent)
		local chosenItem = getRandomItem(randNum)
		event:FireServer("Open", chest, chosenItem)
		print("Button Pressed")
	end
end)

instead of event:FireServer(“Open”, chest, chosenItem)
can you do event:FireServer(chosenItem , “Open”, chest)
since above you said

local Items = game.SeverStorage.Items:GetChildren()
giveItemsEvent.OnSeverEvent:Connect(function(player, chosenItem) --the seconfdargument is chosenitem but when firing you made the fourth argument

oh i just make it shorter for yall easy to read. Its actually look like

event.OnServerEvent:Connect(function(player, instruction, chest, chosenItem)

is GetRandomItem a function? what does it do?
also print the chosenItem in the local script too(before firing)

First my item table look like this:

local items = {

{"Sword", 50},

{"Heavy Sword", 20},
--"Weapon Name", Percent Rate %
}

yea GetRandomItem is a function. math stuff idk how to explains. Basically its give me a random item based on the percent rate

i tried print the chosenItem (both local and sever script) it does printing out the item name like “Sword” or sometime is “Heavy Sword” cuz its random

so it prints the name of the item in local but nil in server, and the percentage is 70 right? in math,random

no no if i print the chosenItem both on local and sever its does give me the name of the item but if i do printing Items[chosenItem] on sever its give me nil

i think ik whats wrong, youre using string to find an object, try using index like this
Items[1]
the first item is sword, second is heavy sword.
so use index
Screen Shot 2022-10-27 at 8.46.41 PM
^example

the item folder also looks like this, a table(assuming you did Items:GetChildren())

also one thing , the way you were doing is for dictionaries
(things that look like this)
local Dictionary =
{
[“Sword”] = 5,
[“heavySword”] = 10,
[“gun”] = 20
}
an table looks like this
local Table = {“Sword” , “HeavySword”,“Gun”}

so

Table[“Sword”] will give u nill
Table[2] will give you “HeavySword”
Dictionary[“Sword”] = will give you. [“Sword”] = 5