Random Spawning Enemies

Hello,

I need a bit of help. I’m making a open world type of game that needs enemies in it. But because its infinite generation and there’s a max render I need a way of spawning Parts for a starter around the player.

I could not find any tutorials on this so i have came to the dev forum for help.

Thanks Have a good one.

1 Like

To get a new NPC spawn position close to the player I would suggest using the player Position and then adding a Vector3 with some randoms in it, so:

local radius = 20    -- Change this value to how far you want max spawn pos to be
local NPCspawnPos = aCharacter.PrimaryPart.Position + Vector3.new(math.random(-radius , radius ), 3, math.random(-radius , radius )
-- The "3" is the helight NPC will spawn at, so around Hip Height
2 Likes

Ill try it out as soon as possible

Hello,

I have tried many things with this script it is not working as intended,
Where does it go?
Where do I put my enemy model?
Heres some screenshots of the output and more:


image image

Check if you have anything like this:

game.Players.LocalPlayer.Character.Torso

Torso is outdated, it’s now HumanoidRootPart,
Change it to:

game.Players.LocalPlayer.Character.HumanoidRootPart
1 Like

It doesn’t look like he’s using R15 but rather R6.
also yes, it is outdated. Humanoid.Torso (roblox.com)

1 Like

yes thats what im doing should i change the rig to r6?

Just use HumanoidRootPart instead of Torso

1 Like

no you shouldn’t. just change it to what i wrote

1 Like

Ill get my buddy to try since i am doing something atm

You named your Zombie, zombietest. Fix the name :confused:

1 Like

that was a old screenshot its the same name.

Wrote a quick script for you.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
         local Enemy = ReplicatedStorage.Enemy:Clone()
         Enemy.HumanoidRootPart.Position = Character.HumanoidRootPart.Position +     Vector3.new(math.random(-20,20),3,math.random(-20,20))
         Enemy.Parent = workspace
    end)
end)
1 Like

It works perfectly and I can work off it. Thank you so much I hope u have a great day.

1 Like