ServerScriptService.GearRandomizer:3: attempt to index nil with 'Character'

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)

You cannot do .LocalPlayer inside of a server side script

1 Like

I fixed the bug

(character limit)