Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I use Spawn Function is this correct?

Why isn't this working

Zombie = game.ServerStorage.Zombie
cz = Zombie:Clone(workspace)
spawn(cz)

2 answers

✓ Accepted answer

What are you trying to achieve with this script? And a quick search shows the correct usage of spawn(), "Spawn is used to run a function in a separate thread without yielding the current one. It will run simultaneously with the rest of the tasks, but won’t delay/affect the main thread." If you are trying to 'spawn' a zombie into the game you would clone it to the workspace(which you have done), and then set it's position to wherever you want it to appear.

EDIT: there would be at least two ways to make it 'spawn' you would either specify the position it should be at, like this

Zombie = game.ServerStorage.Zombie
cz = Zombie:Clone()
cz.Parent = game.Workspace
cz.UpperTorso.Position = Vector3.new(0, 0, 0)

Or, you could set a block in the workspace that is invisible and has can collide off, and you would do something like this

Zombie = game.ServerStorage.Zombie
cz = Zombie:Clone()
cz.Parent = game.Workspace
cz.UpperTorso.Position = workspace.czspawn.Position

If you have any other problems or questions just let me know

4 comments

0

How can I set the spawn? Thx

0

let me know if it worked or not so i can see if I can find the problem

0

It still dosen't work,I'm not sure why

0

I tested it out and found an error, try the edited code now

No, that is not how you use it. It is used to spawn functions while going on with the script. Their most common use is with while true do loops, like this one:

local function doLoop()
	while true do
		print("Hello World!")
		wait()
	end
end

spawn(doLoop)

while true do 
	print("Bob")
	wait()
end

Both while true do's will run.

This discussion is preserved as it was. New answers, comments, and votes are closed.