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

Why is my random location orb spawner not working?

Hi there so I am learning to script and I was able to come up with this for a random spawner basically like blox fruits where the part spawns on random parts around the map to give you powers.

I am able to clone the parts and i am getting the positions i need but the parts that are being cloned are not actually being placed where they should be they are only being placed at 0,0,0.

help please here is the code below

local orbs = game.Lighting.Orbs:GetChildren()
local positions = game.Workspace.OrbPositions:GetChildren()

for i, v in pairs(positions, 1) do
	pos = v.Position
	print(pos)
end

for i, v in pairs(orbs, 1) do
	wait(5)
	local cloned = v:Clone()
	cloned.Parent = game.Workspace
	cloned.Position = Vector3.new(pos)
end

1 comment

0

pairs() only takes one argument

1 answer

You're not even trying to put them at random locations, because pos always ends up being equal to positions[#positions], which is apparently (0,0,0). How about using math.random() instead of iterating through a table and getting the same position every single time?

pos = positions[math.random(1, #positions)].Position

I really don't understand your intention of looping to find a random value.

5 comments

0

I believe he wanted to take one position from the first loop, then use that position in the second loop, then repeat

0

And on your solution proposition you frogot .Position at the end

0

It's not random and it never will be. It's always (0,0,0). Read his code before making a remark.

0

What, no I agree with you. I know it won't be random. I just said I think that's what he was trying to do

0

Sorry for the confusion its random to people who are playing the game but i want them to spawn where i have parts set around the map. This is why i am running it but i want it to be spawned every hour at one of the part locations.

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