Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
iacnan 0
9 years ago

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.

0
any error messages? why is there a 0 second delay? lukeb50 631 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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.

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 lukeb50 631 — 9y
Ad

Answer this question