YouTube Tutorials:
Spawn NPCs Instantly During Gameplay with Only 2 Lines of Code! (DummyService)
Introducing DummyService
Hello!
Roblox doesn’t make it an easy or efficient task to create and spawn NPCs quickly and easily. They don’t have a service where you can simply spawn NPCs by just running a function. Today that changes!
What is DummyService?
I introduce to you: DummyService, the easiest and most versatile… Yeah yeah, you’ve read the title.
Think of DummyService as an Instance.new()
for NPCs. You can simply just add an NPC and clone it to wherever you want. But if you want to easily create diverse and advanced NPCs with one function, you’re at the right place.
What Can DummyService Do?
DummyService is a ModuleScript that lets you:
- Spawn Dummies
- Get and Manage Dummies
- Remove Dummies
There are so many things you can actually do with this script, and I’m going to explain to you how to do them. Make sure to put the ModuleScript inside ServerScriptService
first.
Functionality
1. How to Create a Dummy: SpawnDummy()
DummyService has many, many arguments, especially when spawning dummies. I wanted to make sure that you could make any kind of dummy easily with no limit or restriction.
Parameters
-
1. dummyType (Number Value)
(Required)
There are 5 dummy bases that you can choose from:- R6 Block: The one and only R6 Block Rig. Common in games like Strongest Battlegrounds. (1)
- R6 Basic: The non-blocky R6 character that uses CharacterMeshes. Used mainly in games that accept all R6 body types. (2)
- R15 Block: Like the R6 Block, but with more parts. (3)
- R15 Basic: The default Roblox character rig. This type is used in the starter bacon hair character. (4)
- Rthro Skinned: The newest and most modern character type. (5)
-
2. dummyName (String Value)
The name of the dummy instance. Not much else to say. -
3. dummyTag (String Value)
(Recommended)
The tag of the dummy. This is required if you want to manage or delete your dummy in the future. -
4. customHumanoidDescription (HumanoidDescription Instance)
The HumanoidDescription of the dummy. If left blank, the dummy will have no HumanoidDescription or will embody the HumanoidDescription of the next parameter. -
5. embodiedAvatar (String: Roblox Player Username)
If you didn’t fill out the last parameter, this can be used to set the dummy’s HumanoidDescription to a Roblox player’s avatar.- Set this to
"none"
if you don’t want to use this parameter. -
Do not set it to
nil
, or the script will break. - If both this and the previous parameter are empty, the dummy will have no HumanoidDescription.
- Set this to
-
6. position (CFrame)
(Required)
The position where the dummy will spawn. -
7. parent (Instance)
(Required)
What the dummy will be parented to. -
8 & 9. itemsInsideDummy (Folder)
andwhereInDummy (Instance in Dummy)
Use these to add custom scripts or anything else inside the dummy.-
itemsInsideDummy
: A folder containing the items to be inserted. -
whereInDummy
: Where to place the items inside the dummy (e.g., “HumanoidRootPart”). Ifnil
, the items will go directly inside the dummy.
-
-
10. timeBeforeParented (Number)
A parameter that controls how long it takes for the dummy to be parented. Default is
0
.
-11. doesRespawn (Boolean)
A parameter that if enabled, the dummy will recreate itself after its Humanoid.Health
reaches zero.
-12. timeBeforeRespawn (Number)
If the doesRespawn boolean is enabled, this will control how long it takes for the dummy to recreate itself. Note that if you also have the timeBeforeParented
value set to something, it will take more time for the dummy to be re-parented.
2. How to Get/Manage Your Dummy: FindDummy()
Use this function to retrieve your dummy instance based on its DummyTag
. This function is simpler than SpawnDummy
.
Parameters
-
DummyTag (String)
(Required)
The tag of the dummy(s) to find. -
where (Instance)
(Required)
Where to search for the dummy. Default is thegame
instance. -
when (Number)
(Optional)
A delay before searching. Default is0
.
3. How to Delete Your Dummy: DeleteDummy()
This function works similarly to FindDummy()
but deletes the dummy instead.
Parameters
-
DummyTag (String)
(Required)
The tag of the dummy(s) to delete. -
where (Instance)
(Required)
Where to search for the dummy. Default is thegame
instance. -
when (Number)
(Optional)
A delay before deletion. Default is0
.
Code Examples
Example 1: Basic Avatar-Embodying NPC
local dummyService = require(game.ServerScriptService:WaitForChild("DummyService"))
dummyService.SpawnDummy(
2, -- R6 Basic character
"Bob", -- Name of the dummy instance
"Citizens", -- Tag to identify the dummy later
nil, -- No custom description
"Roblox", -- Use the avatar of the user "Roblox"
CFrame.new(0, 5, 0), -- Spawn location
game.Workspace -- Parent to Workspace
)
Example 2: Spawn NPC After 5 Seconds
dummyService.SpawnDummy(
2, "Bob", "Citizens", nil, "Roblox", CFrame.new(0, 5, 0), game.Workspace, nil, nil, 5
)
Example 3: Spawn, Get, and Delete Dummy
local dummyService = require(game.ServerScriptService:WaitForChild("DummyService"))
dummyService.SpawnDummy(3, "Bob", "GoodCitizen", nil, "Robloxco0lgame", CFrame.new(0,5,0), game.Workspace)
local outputDummy = dummyService.FindDummy("GoodCitizen", game.Workspace)
print(outputDummy.Name)
task.wait(2)
dummyService.DeleteDummy("GoodCitizen", game.Workspace, 5)
Troubleshooting
-
CustomHumanoidDescription and EmbodiedAvatar Conflict?
Avoid using both parameters simultaneously. -
Nil Error?
Ensure all required parameters are filled out. -
EmbodiedAvatar Set to
nil
?
Use"none"
instead.
If you’re still having trouble, reply to this post or DM me for help!
Module Link
Update Log (V1.2)
- Created a new function to spawn very, very bare bones dummies.
SpawnSimpleDummy()
- Added two new parameters in the
SpawnDummy()
function that let you respawn dummies after they die and after a certain time.
Coming soon: Appearance preloading, humanoid settings
Thank you for checking out DummyService!