generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: NPC respawn script

Previous Thread :: Next Thread 
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
04 Jul 2014 04:30 PM
I have this script inside of an NPC;

script.Parent.Humanoid.Died:connect(function(res)
local modl = game.ServerStorage.Hollow
local times = math.random(1,10)
if (script.Parent.Humanoid.Health) == 0 then
wait(times)
vr = modl:Clone()
vr.Parent = game.Workspace
vr:MakeJoints()

vr:MoveTo(script.Parent.Head.Position)

script.Parent:Destroy()
end
end)

Whenever the NPC dies it is supposed to respawn between 1 to 10 seconds. But the problem is it works one time in test mode, and stops working after the second time that NPC is killed. And it doesn't work at all in-game. Help? What to do?
Report Abuse
nobbers12345 is not online. nobbers12345
Joined: 06 Feb 2011
Total Posts: 4425
04 Jul 2014 04:44 PM
function respawn ()
local modl = game.ServerStorage.Hollow
local times = math.random(1,10)
local health = script.Parent.Humanoid.Health
if health == 0 then
wait (times)
vr = modl:Clone()
vr.Parent = game.Workspace
vr:MakeJoints()
vr:MoveTo(script.Parent.Head.Position
end
end

local NPC = script.Parent.Humanoid
Humanoid.Died:connect(respawn)

I hate the LGBT. Those laser guided battle tanks are just too damn powerful.
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
04 Jul 2014 06:18 PM
This didn't change anything. All that was changed was the anonymous function.
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
04 Jul 2014 06:31 PM
Bump
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
04 Jul 2014 06:37 PM
Bump[2]
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
04 Jul 2014 06:43 PM
. . .
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
04 Jul 2014 06:49 PM
4
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
04 Jul 2014 06:51 PM
script.Parent.Humanoid.Died:connect(function(res)
local modl = game.ServerStorage.Hollow
local times = math.random(1,10)
--if (script.Parent.Humanoid.Health) == 0 then--wth do you have this
wait(times)
vr = modl:Clone()
vr.Parent = game.Workspace
vr:MakeJoints()

vr:MoveTo(script.Parent.Head.Position)

script.Parent:Destroy()
--end
end)
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
04 Jul 2014 06:59 PM
So that a new NPC respawns when one dies.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
04 Jul 2014 07:07 PM
U already have the .Died event -_-
Don't do that, because sometimes health can go below 0 I believe.
Report Abuse
fireblade2 is not online. fireblade2
Joined: 18 Nov 2007
Total Posts: 4666
04 Jul 2014 07:13 PM
local modl = game.ServerStorage.Hollow


function respawn()
local vr = modl:Clone()

vr.Died:connect(function()
local times = math.random(1,10)
wait(times)
vr:Destroy()
return respawn()
end)

vr.Parent = game.Workspace
vr:MakeJoints()
vr:MoveTo(Vector3.new(0,0,0)) --Change this to a position

end

script.Parent.Humanoid.Died:connect(function()
local times = math.random(1,10)
wait(times)
script.Parent:Destroy()
respawn()
end)


--Tell me if this works, it's not pretty, but it's going off of your original script

Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
04 Jul 2014 07:17 PM
fire.. a model cannot die...

local vr = modl:Clone()

vr.Died:connect(function()


and I never see a definition of modl
Report Abuse
fireblade2 is not online. fireblade2
Joined: 18 Nov 2007
Total Posts: 4666
04 Jul 2014 07:20 PM
First line is 'local modl = ...' , and change vr.Died to vr.Humanoid.Died, I typed that kind of fast.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
04 Jul 2014 07:20 PM
nvm I do :D
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
05 Jul 2014 11:32 AM
Sorry but it is not doing anything at all, I've edited it to this.

local modl = game.ServerStorage.Hollow


function respawn()
local vr = modl:Clone()

vr.Humanoid.Died:connect(function()
local times = math.random(1,10)
wait(times)
vr:Destroy()
return respawn()
end)

vr.Parent = game.Workspace
vr:MakeJoints()
vr:MoveTo(game.Workspace.PartSpawn.Position)

end

script.Parent.Humanoid.Died:connect(function()
local times = math.random(1,10)
wait(times)
script.Parent:Destroy()
respawn()
end)
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
05 Jul 2014 11:40 AM
Bump
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
05 Jul 2014 11:46 AM
6
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
05 Jul 2014 11:49 AM
7
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
05 Jul 2014 12:02 PM
8
Report Abuse
fireblade2 is not online. fireblade2
Joined: 18 Nov 2007
Total Posts: 4666
05 Jul 2014 12:03 PM
Is hollow the same thing as script.Parent? Or after script.Parent dies it's replaced with an entirely different model?
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
05 Jul 2014 12:06 PM
after script.Parent dies it's replaced with an entirely different model but with the same name "hollow"
Report Abuse
fireblade2 is not online. fireblade2
Joined: 18 Nov 2007
Total Posts: 4666
05 Jul 2014 12:09 PM
I meant to say the model is different in terms of instances, it doesn't look exactly like the original model and it doesn't have the same scripts or hierarchy?
Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
05 Jul 2014 12:10 PM
Oh, it does look exactly like the other model, and it has the same scripts inside of it. See, when the current NPC in workspace dies, the same one from ServerStorage is supposed to be cloned into workspace.
Report Abuse
fireblade2 is not online. fireblade2
Joined: 18 Nov 2007
Total Posts: 4666
05 Jul 2014 12:14 PM
Okay, put this inside the original model:


local figure = script.Parent:clone()

script.Parent.Died:connect(function()
local figure2 = figure:clone()
figure2.Parent = script.Parent.Parent
figure2:MakeJoints()
script.Parent:Destroy()
end)


Report Abuse
Kasumo is not online. Kasumo
Joined: 22 Mar 2013
Total Posts: 2467
05 Jul 2014 12:21 PM
Thank you, it works! Would you happen to know where I could implement a wait time before they respawn?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image