#why doesnt my npc die normally

1 messages · Page 1 of 1 (latest)

lapis yacht
#

I want it to die as if he reset and not just stand there loll

cyan fjord
#

make sure the NPC is unanchored and BreakJointsOnDeath is true inside the Humanoid

lapis yacht
cyan fjord
#

just click the NPC and uncheck this button at the top

lapis yacht
#

holy you're genious

cyan fjord
#

did it fix everything?

lapis yacht
#

yeah it did bro thanks

cyan fjord
#

nice, np

lapis yacht
#

also if u didnt mind me asking, how would I go about making it respawn

short steppeBOT
#

studio** You are now Level 1! **studio

lapis yacht
#

like a bloxfruits npc

cyan fjord
#

you would have to make a script probably that clones the NPC

#

first drag your NPC into ReplicatedStorage

#

you can keep it named "Shark03D" if you want you just have to make sure it lines up in the script

#

i'll write a simple script that should work

lapis yacht
#

so basically I have to clone it to the workspace whenever one dies?

cyan fjord
#

yes

#

i can make the script it if u want? it'll take like a minute

lapis yacht
#

I mean sure if u want, just as long as I can learn from it

cyan fjord
#

ok i can comment everything i do inside the code?

#

to try and show what im doing

lapis yacht
#

yeah thanks

cyan fjord
#

how much coding knowledge do you have already?

lapis yacht
#

hmmm

#

I literally started using studio like 2 weeks ago and ive been learning scripting from yt tutoiral serires lol

#

I can understand what a lot of stuff does but if I dont know how to use it myself ill watch tutorials to learn it

cyan fjord
#

alr ill try my best to explain everything

lapis yacht
#

thanks

cyan fjord
#

here you go

Put this in a new script inside ServerScriptService:

local NPC = game.ReplicatedStorage:WaitForChild("Shark03D")
-- Get the NPC above, and wait for it if it hasnt loaded in yet.
-- Stores it into the variable named "NPC" so we can easily reference it.

function createNPC() -- create a new function to spawn the NPC
  local clone = NPC:Clone()
  clone.Parent = workspace
  -- The code above creates a clone of the NPC and puts it inside workspace
  
  local humanoid = clone:WaitForChild("Humanoid") -- wait for the clone's humanoid to load in and store it inside a variable
  
  humanoid.Died:Connect(function()
    task.wait(1)
    createNPC()
    clone:Destroy()
  end)
  -- Above connects a new function that will run once the clone has died
  -- it will run the function "createNPC" again 1 second after its death
  -- then it will destroy the old clone that already died

end

createNPC() -- calls the function to create the very first NPC
#

and here is the same code without the comments

local NPC = game.ReplicatedStorage:WaitForChild("Shark03D")

function createNPC()
    local clone = NPC:Clone()
    clone.Parent = workspace
    local humanoid = clone:WaitForChild("Humanoid")
    humanoid.Died:Connect(function()
        task.wait(1)
        createNPC()
        clone:Destroy()
    end)
end

createNPC()
lapis yacht
#

yoo bro I cant thank you enough

cyan fjord
#

its np, let me know if you need any more help with it

lapis yacht
#

when u said 'function createNPC()' why isnt there a local infront? im just curious because a lot of the time most variables or functions start with local

cyan fjord
#

You can make that function local if you wanted, normally i would too but i left it out to keep it simple. Most variables and functions you would put local behind, except for functions that aren't inside any other functions. Those don't have to have local in front

#

like this for example, test1 works with or without a local in front. but test2 needs a local in front because its inside test1. That means test2 can only be called within test1

function test1()
  local function test2()
    print('something')
  end
  test2()
end
test1()
lapis yacht
#

so scope has something to do with it?

cyan fjord
#

yeah excluding local means it is a global function that can be called anywhere in the script basically

lapis yacht
#

bro its crazy how helpful you are lol

short steppeBOT
#

studio** You are now Level 2! **studio

lapis yacht
#

I understand everything youve said

cyan fjord
#

ty wow, im glad i was able to help

#

im not used to teaching people but i have a lot of experience programming

lapis yacht
#

thats fair

#

Im confused on how you wrote the scripts inside a blue box, like is it a discord feature?

cyan fjord
#

yes type it like this
```lua
-- code inside here
```

#

thats how you type formatted code by surrounding it with "```" and then the name of the language following that if its supported

lapis yacht
#
print("hi)
#

thats cool

cyan fjord
#

yeah

#

its pretty useful

lapis yacht
#

fr

#

well Imma go play some clash royale

#

thanks for the help