Please explain REALLY DETAILLED what it is you’d like to do with that script.
You want the noob to respawn on the brick? Then I would just make 2 teams, make 2 spawns, set the spawns each to one of the teams, and team the noob team 1 (or 2). Then he respawns on the spawn you set to the team the noob is in.
Insert a Script inside the NPC (noob), then copy paste the code below into the Script you just inserted.
Edit the RESPAWN_BRICK and RESPAWN_TIME variables.
If you need help with editing those variables just reply.
Make sure the NPC has a HumanoidRootPart and a Humanoid.
NPC Code
local humanoid = model:FindFirstChildOfClass('Humanoid')
local clone = model:Clone()
local RESPAWN_BRICK = workspace.RespawnBrick -- where the NPC would respawn
local RESPAWN_TIME = 6 -- number of seconds to respawn after the NPC has died
humanoid.Died:connect(function()
wait(RESPAWN_TIME)
model:Destroy()
clone.Parent = workspace
clone.HumanoidRootPart.CFrame = RESPAWN_BRICK.CFrame * CFrame.new(0, 3, 0)
end)
Yes so I have just did what you said and i think im doing something wrong, so the script below the one i just inserted was a script for chasing the player until it dies.
– local larm = script.Parent:FindFirstChild(“HumanoidRootPart”)
local rarm = script.Parent:FindFirstChild(“HumanoidRootPart”)
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 10000
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == “Model”) and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild(“HumanoidRootPart”)
human = temp2:findFirstChild(“Humanoid”)
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while true do
wait(1)
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent.Zombie:MoveTo(target.Position, target)
end
end
And I have placed it in the respawn script below it and it didn’t respawn, if you have some time may you please help me with it?
That script has some issues. I used to use it before I knew how to use magnitude.
I made this one and it is a lot simpler and it works fine.
function findNearestTorso()
main = math.huge
for i,v in pairs(game.Players:GetChildren()) do
if v.Character then
if (v.Character.HumanoidRootPart.Position - script.Parent.Torso.Position).Magnitude < main then
if v.Character.Humanoid.Health > 0 then
main = (v.Character.HumanoidRootPart.Position - script.Parent.Torso.Position).Magnitude
torso = v.Character.HumanoidRootPart
end
end
end
end
return torso
end
while wait() do
local target = findNearestTorso()
if target ~= nil then
script.Parent.Zombie:MoveTo(target.Position, target)
end
end
Also put it in a different script than the respawn one.