I have found this code from another post in DevForum as a solution… But it just spawn for one time and i am getting 2 error. I will give script and output below. Can someone help?, thanks.
Script:
local humanoid = script.Parent:WaitForChild("Humanoid")
while task.wait(3) do
if humanoid.Health <= 0 then
local dummyBackup = game.ServerStorage.NPC1:Clone()
script.Parent:Destroy()
dummyBackup.Parent = workspace.VS
dummyBackup.HumanoidRootPart.CFrame = game.Workspace.VS.Spawner.CFrame + Vector3.new(0,3.006,0)
dummyBackup:PivotTo(CFrame.new(dummyBackup:GetPivot().Position) * CFrame.Angles(0, math.rad(-90), 0))
dummyBackup.Name = "NPC"
end
end
Output:
-- 03:10:43.297 Workspace.VS.NPC1.Respawn:5: Expected identifier, got 'end' - Studio - Respawn:5
-- 03:10:46.312 Workspace.VS.NPC.Respawn:6: attempt to index nil with 'Destroy' - Studio
But make sure the script is inside the model as this error “Workspace.VS.NPC.Respawn:6: attempt to index nil with ‘Destroy’ - Studio” may be related to where the script was.
NPC1 is duplicated model with this one, just moved NPC1 to ServerStorage. And i named NPC1 to NPC again after clone so the other scripts i referred to NPC can work.
Done Fixed, Thank you for helping man! you are the best @brenorocketstar . full code:
local humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
while task.wait(3) do
if humanoid.Health <= 0 then
local dummyBackup = game.ServerStorage.NPC1:Clone()
game.Workspace.VS.NPC:Destroy()
dummyBackup.Parent = workspace.VS
dummyBackup.HumanoidRootPart.CFrame = game.Workspace.VS.Spawner.CFrame + Vector3.new(0,3.006,0)
dummyBackup:PivotTo(CFrame.new(dummyBackup:GetPivot().Position) * CFrame.Angles(0, math.rad(-90), 0))
dummyBackup.Name = "NPC"
end
end