Roblox Lua Script Producing Error

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I wanna make my drill work and produce ores

  1. What is the issue? Include screenshots / videos if possible!

This script:

local itemsfolder = game.Lighting.Ores:GetChildren()
local item = math.random(#itemsfolder)

local DrillTime = 3


if script.Parent.Mining.Value == true then
	while wait(DrillTime) do
		
		item = math.random(#itemsfolder):Clone()
		item.Parent = workspace.Ores
		item.Position = script.Parent.DropLocation.Position
		


	end
	
	
	
end

Displays error:

  13:48:36.860  Workspace.Model.Script:10: attempt to index number with 'Clone' 

uhh i think you should make a devforum post about this

This is the devforum site? What do you mean

yes but like on the devforum the actual devforum

Isnt the app and site the official devforum?

When getting a random item from a folder it’s used like this:

local item = itemsfolder[math.random(1, #itemsfolder)]

it works the other way too, and i tried that way and still got the same error.

You could try:

local number = math.random(#itemsfolder)
local randomItem = itemsfolder[number]

1 Like

It works! I have never seen a method like that before but thanks for helping

1 Like

Wait but I made my script like this

local itemsfolder = game.Lighting.Ores:GetChildren()
local number = math.random(#itemsfolder)
local randomItem = itemsfolder[number]

local DrillTime = 3


if script.Parent.Mining.Value == true then
	while wait(DrillTime) do

		number = itemsfolder[number]
		randomItem = number:Clone()
		
		randomItem.Parent = workspace.Ores
		randomItem.Position = script.Parent.DropLocation.Position



	end



end

and now errors same error

image

Maybe something like this will work?

local itemsfolder = game.Lighting.Ores

local Items = {}
local DrillTime = 3

for i, v in itemsfolder:GetChildren() do
	table.insert(Items, v)
end

if script.Parent.Mining.Value == true then
	while task.wait(DrillTime) do
		
		local randomItem = Items[math.random(1, #Items)]:Clone()
		randomItem.Parent = workspace.Ores
		randomItem.Position = script.Parent.DropLocation.Position
	end
end
1 Like

This worked when I tested it. So try this and see if this works. ¯_(ツ)_/¯

local itemsfolder = game.Lighting.Ores:GetChildren()

local DrillTime = 3

if script.Parent.dril.Value == true then
while wait(DrillTime) do
local number = math.random(#itemsfolder)
local randomItem = itemsfolder[number]
if randomItem then

		print(randomItem)
		local Item = randomItem:Clone()
		print(Item)
	

		Item.Parent = workspace.Ores
		Item.Position = script.Parent.DropLocation.Position


	end
end

end

1 Like

Both of your solutions work, thank you both for helping

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.