Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

NPC stops following player?

Asked by 5 years ago

Hello guys again! I come to you with a new issue.

In the game I am making, I have a script that makes the NPC follow the player, but..

If the player gets hit by the enemy mob and dies, the enemy mob continues following the player when the player respawns as it is expected to do. However..since there are gaps players are to jump over, if the player falls into the void; the enemy NPC wont follow the player after the player respawns.

local aihumroot = script.Parent.HumanoidRootPart
local aihum = script.Parent.Humanoid

while true do
    for _,plr in pairs(game.Players:GetPlayers()) do
        if plr.Character then
            local char = plr.Character
            if (char.HumanoidRootPart.Position-aihumroot.Position).magnitude <= 30 then
                aihum:MoveTo(char.HumanoidRootPart.Position)
            end
        end
    end
    wait()
end

This is the current code I have.

(credit to Eagle022 for helping me simplify and understand where I went wrong in my original code btw)

0
does the code error when you jump into the void? megukoo 877 — 5y
0
where can i find the syntax errors on studio? i had no idea they existed on roblox studio piemaster347alt 17 — 5y
0
here it is; 17:33:29.706 - HumanoidRootPart is not a valid member of Model 17:33:29.706 - Stack Begin 17:33:29.708 - Script 'Workspace.Drooling Zombie.Script', Line 8 17:33:29.709 - Stack End 17:33:29.724 - HumanoidRootPart is not a valid member of Model piemaster347alt 17 — 5y
0
That just means that you don't have "HumanoidRootPart" defined in the CharacterModel of the NPC. BryanFehr 133 — 5y
0
When a player's Humanoid dies, their character is (usually) reset. You have to add an if statement to check if the HumanoidRootPart exists before checking the magnitude of its relative position to the AI's position. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by
NSMascot 113
5 years ago

maybe do this when the players character is loaded also add the enemy into the lighting

local position = game.Workspace.(enemynamehere).HumanoidRootPart.CFrame
game.Workspace.(enemynamehere):Remove()
game.Lighting.(enemynamehere):Clone().Parent = game.Workspace
 game.Workspace.(enemynamehere).HumanoidRootPart.CFrame = position

might not work, might be wrong, I just thought of it at the top of my head, its not the most effective & practical way but it might work, enjoy, :)!!!!!!!

Ad

Answer this question