Answered by
4 years ago Edited 4 years ago
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:
01 | local Gears = game.ServerStorage.Gears:GetChildren() |
03 | script.Parent.Touched:Connect( function (Hit) |
04 | if Hit.Parent:FindFirstChild( "Humanoid" ) then |
05 | local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) |
06 | local Inventory = Player.Backpack |
07 | local RandomGearIndex = math.random( 1 , #Gears) |
08 | local RandomGear = Gears [ RandomGearIndex ] |
09 | RandomGear.Parent = Inventory |
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.