My NPC should follow any random player within 50 studs. The problem is when I die the NPC just kept walking to the spot I died. I printed the part it’s touching and realized that my body part are still there after I’ve died. Here is my script
function checkPlayer(COOLDOWN)
local filter = OverlapParams.new()
filter.FilterDescendantsInstances = {script.Parent}
filter.FilterType = Enum.RaycastFilterType.Exclude
local partArray = workspace:GetPartBoundsInBox(hitbox.CFrame, hitbox.Size, filter)
for _,part in pairs(partArray) do
if part.Parent ~= nil then
print(part.Name .. part.Parent.Name)
local playerHum = part.Parent:FindFirstChildOfClass("Humanoid")
if playerHum and hitting == false then
hitting = true
playerHum.Health -= 100
wait(COOLDOWN)
hitting = false
end
else end
end
end
function followPlayer()
for i,player in pairs(game.Players:GetPlayers()) do
if player ~= nil then
if (script.Parent:FindFirstChild("HumanoidRootPart").Position-player.Character:FindFirstChild("HumanoidRootPart").Position).Magnitude < 50 and player.state.Value == false then
local playerHideState = player.state.Value
humanoid:MoveTo(player.Character:FindFirstChild("HumanoidRootPart").Position)
end
else
local path = pathlists[math.random(1,#pathlists)]
humanoid:MoveTo(path.Position)
end
checkPlayer(2)
end
end
while true do
followPlayer()
wait(.5)
end
After that I tried making another script to destroy all descendants after the character dies. The output says it’s not touching anything but it still won’t move away from the spot I died
I don’t understand how respawning in Roblox works. Can someone explain why my NPC isn’t working properly?
thanks