01 | local REMOTE = Instance.new( "RemoteEvent" ) |
02 | REMOTE.Name = "Box_event" |
03 | REMOTE.Parent = game.ReplicatedStorage |
04 |
05 |
06 |
07 | game.ReplicatedStorage.Box_event.OnServerEvent:Connect( function (Player,Item) |
08 | local ItemsList = game.ServerStorage.Items:GetChildren() |
09 | if (Player.Character.HumanoidRootPart.Position - Item.Position).magnitude < 10 then |
10 | local ChosenItem = math.random( 1 , #ItemsList) |
11 | local Clone = game.ServerStorage.Items [ ChosenItem ] :Clone() -- problem |
12 | Clone.Parent = Player.Backpack |
13 | end |
14 | end ) |
On the math.random, I want it to choose a number and on the next line, copy that tool that is that number in the folder. But it only returns a number instead.
You're actually very close. Your ItemsList table has an index of all of the items in the folder already, so after using math.random(1, #ItemsList), there is no need to retrieve the folder again, you could just do
local Clone = ItemsList[ChosenItem]:Clone()
or even
local Clone = ItemsList[math.random(1, #ItemsList)]:Clone()
and save a line.
Edit: I should probably also explain why you can pull it from ItemsList and not from the folder itself. The ItemsList that gets the children from the folder is a table that recognizes the position in the table as a numeric value, whereas the folder itself doesn't recognize a position as a child.