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.

lastkey = nil

function SpawnKeys()
    keys = game.Workspace.Map.Main.GameKey:GetChildren()
    pickedkeys = math.random(1, #keys)
    if keys[pickedkeys].Name == lastkey then
        SpawnKeys()
    else
        lastkey = keys[pickedkeys].Name
        for i = 1, #keys do
        local keyspawns = game.Workspace.Map.Main.keyspawn.KeyParts
        keys[i].Position = keyspawns.Position
        keyspawns:Remove()
        end
    end
end

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