Randomizer Spawn for NPC

I’m looking to make a randomizer spawn location for a monster in our game, but don’t understand how to… I’ve made a folder with the “Spawns” such as: “Cave, Cave2, Cave3” but don’t know how to get it to spawn between. It’s currently on a day and night script during the night it spawns in and morning it’s supposed to go into the serverstorage.


I suggest you try placing more than one on different Time cycles. Hope this helps!

What? It’s supposed to disappear during the day and spawn at night. It’s for a game, only 1 monster and it’ll get repetitive spawning in only one location.

--try this:
    --put this script in the mob
    local a = script.Parent
    local c = a:Clone()
    local b = math.random(1,3)
    if b == 1 then
    c.Parent = workspace
    c.HumanoidRootPart.CFrame = workspace.Spawns.Cave.CFrame
    elseif b == 2 then
    c.Parent = workspace
    c.HumanoidRootPart.CFrame = workspace.Spawns.Cave2.CFrame
    elseif b == 3 then
    c.Parent = workspace
    c.HumanoidRootPart.CFrame = workspace.Spawns.Cave3.CFrame
1 Like

Okay, I’ll try it thank you alot.

You can make the script more shorter like put c.Parent = workspace under local b
You can change CFrame to Position if u want
I hope this script will work for you

This is way to complicated, for begineer developers its too hard.

I recommended this:

local spawns = {cave1,cave2,cave3,cave4}

local character = [your npc]:Clone()
character.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame

[] is used to find something within a table
I used that to get some random choice in spawns.
The # is used to get the length of the table.

math.random(1,#spawns) means random number from 1, total choices.

so basically the spawns table have object values.And you pick a object from it randomly and spawn it.


i forgot this way :frowning: :frowning: :frowning: :frowning:

Its fine lol I just told it its easier

this should be in #help-and-feedback:scripting-support

You should move this to a category where you will be able to receive support for your scripting issue, as mentioned above.

Thank you so much! I appreciate it.

Can you mark it as solution so I can understand it helped you, :wink: