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

How would I make something randomly spawn in a set area?

I've been trying to recreate a IOS game in which on different floors the spikes are randomly generated in different locations. I've hardly ever scripted in my life and have been trying to use a couple of free models to make these works, but they don't seem to work and so I've came here for assistance.

This is what I've gotten from a free model and edited a bit, but it doesn't work.

while true do
c = game.Workshape.Spike:clone()
c.Parent = Workspace
c.Position = Vector3.new(math.random(-60,60), 40, math.random(-60,60))
wait(0)
end

Thank you for any help you give.

1 comment

0

any error messages? why is there a 0 second delay?

1 answer

You're missing game. before Workspace on line 3

Side note: wait(0) is basically useless. Just using wait() without a number will make the script wait for a short time. Use that to avoid overloading stuff.

Another side note: Use a for loop if you want there to be a certain amount of spikes, like so

for i =  1, 10
	lines 2-5 here
end

This will make the code inside the loop run 10 times, creating 10 spikes. You can change 10 to whatever number and the code inside the loop will run that many times.

1 comment

0

based on the code he put in, he wont want it to go X amount of times but forever. also, even if game i not before Workspace it is a valid path

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