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

How to make a part spawn in random locations of the map?

Asked by
Jxdenx 45
6 years ago

This is my attempt:

Basically, I have made 16 different parts for the key to spawn to, but the keys remain in the same spawn, it won't change their position.

01lastkey = nil
02 
03function SpawnKeys()
04    keys = game.Workspace.Map.Main.GameKey:GetChildren()
05    pickedkeys = math.random(1, #keys)
06    if keys[pickedkeys].Name == lastkey then
07        SpawnKeys()
08    else
09        lastkey = keys[pickedkeys].Name
10        for i = 1, #keys do
11        local keyspawns = game.Workspace.Map.Main.keyspawn.KeyParts
12        keys[i].Position = keyspawns.Position
13        keyspawns:Remove()
14        end
15    end
16end

I want the keys to spawn into different locations of the map, but for some reason it stays in the same location every time.

Answer this question