How would i randomize a part faster?

I wanna randomize a part instantly because it could randomize the same part for multiple attempts which takes time, I want it to somehow be instant.

My current code is:

function ChooseRandomBlock()
	local block = nil
	repeat wait()
		local randomblock = script.BlockPos[math.random(1, #script.BlockPos:GetChildren())]
		if not game.Workspace.Levels[Level]:FindFirstChild(randomblock.Name) then
			block = randomblock
		end
	until not (block == nil)
	return block
end

Create an array containing all the parts. Then do your loop, but if it doesn’t work, remove the block from the array.

I mean wouldnt that basically be the same thing? Ill give it a try if you think otherwise. I am trying to somehow find a different method than the loop it self, Because i think the loop is whats taking the time.

You need to remove the wait().

lol haha i guess this is faster if not instantly, For some reason i thought it would crash if i did, But thanks!

Glad it helped! The wait() is only needed if you’re using an infinite loop.

Ill keep this in mind next time, Thanks again.

1 Like

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