The following is suppose get a random gear when a part is touched and clone it to the players inventory. The problem is picking the random gear.
local Gears = game.ServerStorage.Gears:GetChildren() script.Parent.Touched:Connect(function(Hit) if Hit.Parent:FindFirstChild("Humanoid") then local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) local Inventory = Player.Backpack local RandomGear = math.random(1, #Gears) -- PROBLEM HERE RandomGear.Parent = Inventory end end)
The problem here is that you only have the index for the random gear, not the gear itself. :GetChildren function gives you a table of children of an object. Here is your script's fixed version:
local Gears = game.ServerStorage.Gears:GetChildren() script.Parent.Touched:Connect(function(Hit) if Hit.Parent:FindFirstChild("Humanoid") then local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) local Inventory = Player.Backpack local RandomGearIndex = math.random(1, #Gears) -- PROBLEM HERE local RandomGear = Gears[RandomGearIndex] RandomGear.Parent = Inventory end end)
You might also want to add a debounce to your script if you don't want the player to get a lot of gears at once but I won't include that here.