local crate = game.Lighting.Crates local med = crate.MedBag:GetChildren() local woodencrate = crate.WoodenCrate:GetChildren() local militarycrate = crate.MilitaryCrate:GetChildren() local m = math.random(1,6)
game.Players.PlayerAdded:connect(function(player) local plr = player
while true do
if m == 1 then
med:Clone().Parent = script.Parent --Error is here
med.CFrame = CFrame.new(-206, 4.2, 225)
end
if m == 2 then
med:Clone().Parent = script.Parent
med.CFrame = CFrame.new(-206, 4.2, 225)
end
if m == 3 then
med:Clone().Parent = script.Parent
med.CFrame = CFrame.new(-206, 4.2, 225)
end
if m == 4 then
med:Clone().Parent = script.Parent
med.CFrame = CFrame.new(-206, 4.2, 225)
end
if m == 5 then
woodencrate:Clone().Parent = script.Parent
woodencrate.CFrame = CFrame.new(-200, 4.2, 240)
end
if m == 6 then
woodencrate:Clone().Parent = script.Parent
woodencrate.CFrame = CFrame.new(-200, 4.2, 240)
end
wait (500) --Restart
script.Parent:FindFirstChild("MedBag"):Destroy()
script.Parent:FindFirstChild("MilitaryCrate"):Destroy()
end
end)

2 comments
means the med variable is nil and fyi, :connect() is deprecated (use :Connect())
so will using :Connected()) fix the issue?