Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't my script cloning things into the workspace?

I'm making a boss fight. And I'm trying to produce a ton of random red circles where bombs will appear a second later. But nothing's happening. Here's my code:

local Positions2 = {-2091.378, 557.797, -1284.397,
		-2105.736, 557.797, -1275.397,
		-2124.513, 557.797, -1299.416,
		-2111.948, 557.797, -1305.343,
		-2113.169, 557.797, -1291.396,
		-2097.229, 557.797, -1290.002,
		-2096.184, 557.797, -1301.956,
		-2122.483, 557.797, -1288.196,
		-2134.437, 557.797, -1289.242,
		-2116.549, 557.797, -1267.6,
		-2129.054, 557.797, -1250.881,
		-2118.168, 557.797, -1234.257,
		-2126.72, 557.797, -1239.769,
		-2113.349, 557.797, -1258.286,
		-2116.182, 557.797, -1245.484,
		-2125.216, 557.797, -1260.328,
		-2117.67, 557.797, -1277.737,
		-2129.011, 557.797, -1270.953,
		-2129.07, 557.797, -1281.745,
		-2137.92, 557.797, -1275.748,
		-2136.442, 557.797, -1266.329,
		-2138.375, 557.797, -1255.711,
		-2138.478, 557.797, -1243.06,
		-2149.34, 557.797, -1259.682,
		-2148.534, 557.797, -1249.318,
		-2105.736, 557.797, -1239.127,
		-2094.378, 557.797, -1238.127,
		-2062.378, 557.797, -1242.421,
		-2080.378, 557.797, -1248.421,
		-2086.125, 557.797, -1261.127,
		-2090.125, 557.797, -1251.421,
		-2098.736, 557.797, -1260.127,
		-2104.736, 557.797, -1286.397,
		-2083.378, 557.797, -1297.69,
		-2093.378, 557.797, -1270.69,
		-2072.378, 557.797, -1293.397,
		-2079.378, 557.797, -1284.397,
		-2062.125, 557.797, -1270.397,
		-2062.378, 557.797, -1280.69,
		-2100.99, 557.797, -1248.127,
		-2070.125, 557.797, -1253.127,
		-2081.378, 557.797, -1236.421,
		-2066.125, 557.797, -1262.421,
		-2075.378, 557.797, -1260.127,
		-2059.378, 557.797, -1254.127,
		-2073.125, 557.797, -1271.397,
		-2083.125, 557.797, -1272.397}
	

	
	for i=1, 30 do
		
		local RedCircle2 = script.RedCircle:Clone()
		
		RedCircle2.Position = Vector3.new(Positions[math.random(1,#Positions)])
		RedCircle2.Parent = workspace
		wait()
	end

And also a side question, does anyone know how I can make an ai generated random pattern? Because making a long table of variables takes a lot of time and looks messy.

2 comments

0

Any OutPut?

0

No

1 answer

It seems like your script IS spawning the red circles, their Y and Z position, however, are both at 0. See in Roblox "Vector3" value is created using "Vector3.new" constructor, in your table you have just random numbers, they are not "Vector3", they are random numbers, this means when you select random number from the table, your new vector looks like this (Positions[math.random(1,#Positions)], 0, 0).

To fix this you need to replace the numbers with vectors:

local Positions2 = {
	Vector3.new(-2091.378, 557.797, -1284.397),
	Vector3.new(-2105.736, 557.797, -1275.397),
	Vector3.new-2124.513, 557.797, -1299.416),
	-- and so on...
}

for i = 1, 30 do
	local RedCircle2 = script.RedCircle:Clone()

	-- no Vector3.new() as it is already constructed in the table
	RedCircle2.Position = Positions[math.random(1,#Positions)]

	-- It'd be better have specific folder for those circles instead
	-- of having everything in the workspace
	RedCircle2.Parent = workspace
	wait()
end

The only thing i can say is that making tables like you did is not necessarily bad but in most cases there might be a better way, for example having an invisible part and spawning them randomly based off of the part size, same can be done with circle if using bit of trigonometry. But that's up to you.

1 comment

0

Thanks a lot.

This discussion is preserved as it was. New answers, comments, and votes are closed.