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)
If you look at what you are defining "med" - local med = crate.MedBag:GetChildren() Why do you need to get the children? If you want to clone the medbag, just state "crate.MedBag". so the correct thing to do:
local med = crate.MedBag while true do if m == 1 then med:Clone().Parent = script.Parent --the only reason the error is here is because it is the first statement that uses it, if you got rid of this statement, the next statement would put out an error 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