Hello. I’m trying to do a Gear Randomizer but it doesn’t work and the output gives me this error: ServerScriptService.GearRandomizer:3: attempt to index nil with ‘Character’. I appreciate any help.
local plr = game:GetService("Players").LocalPlayer
local weapons = game.ReplicatedStorage:FindFirstChild("Weapons")
local character = plr.Character
local hum = character:WaitForChild("Humanoid")
hum.Died:Connect(function()
local function chooserandom(tab)
local n = math.random(1, #tab)
local obj = tab[n]
return obj
end
local gear = chooserandom(weapons:GetChildren()):Clone()
gear.Parent = plr.Backpack
gear.Parent = plr.StarterGear
end)