How do I pick a random meteor, clone it and put the clone in the workspace?

I want to clone a random meteor from the meteors folder inside the script, and put the clone in the workspace, but nothing happens!

I have tried parameters, like in this script:

local meteors = script.Meteors:GetChildren()
local randommeteor = math.random(1, #meteors)
local randomwait = math.random(1, 10)
local meteor = meteors[randommeteor]
	
function DropMeteor()
	if meteors ~= nil then
		while true do
			meteor:Clone().Parent = workspace
			wait(randomwait)
		end
	end
end

DropMeteor(meteor)

Please tell me if I have missed anything or did something wrong!

Oh, and forgot to mention, my script is in the ServerStorage service.

Where is the Script in the Explorer? At a glance, this code seems fine, so it might not be running. Also, are there any errors in the console?

3 Likes
  1. Your locals are set outside the function. Thus, whenever the script is first run, they will always be the same. Put them inside the function to make it choose another meteor every time.

  2. You do meteor:Clone().Parent = workspace As far as I know this isn’t how you would do this. You could either do something like

local cloned = meteor:Clone()
cloned.Parent = workspace

or you could do

meteor:Clone(workspace)

If that doesn’t fix it, try putting print() through your function and see where it stops

1 Like

Why are you putting the meteor as a parameter while the function doesn’t have one?

Try removing it.

1 Like

Sorry, not very good at scripting, when something doesn’t work, I just tinker around. :slightly_smiling_face:

No, only errors that are on Roblox’s side, thanks for helping!

Does not work, thanks for helping!

Can you say where it is in the Explorer, though? Even if the code’s a bit messy, it should still run fine and spawn meteors. If nothing happens at all, the script probably isn’t running.

4 Likes

Just edited it, it’s in the ServerStorage.

Scripts don’t run in ServerStorage, only Workspace and ServerScriptService.

4 Likes

Oh, then should I put it in ServerScript? or ReplicatedStorage?

It doesn’t run in ReplicatedStorage either. I’d just put it in ServerScriptService, yeah.

3 Likes

Thank you, it’s working now! I appreciate the help.

1 Like