Hello! I am wondering If there was a way to make NPCS defend you from hostile mobs. This Is good for making games that have npcs protect you like that clone simulator game (Gave me good times) Got anything?
Hello, you can use something like this:
local goodMob = goodmobLocation -- past here defending mob location local badMob = badMobLocation -- past here bad mob location local players = game:GetService("Players") while wait() do -- infinite checking loop for i, v in pairs(players:GetChildren()) do local char = v:WaitForChild("Character") local hrp = char:WaitForChild("HumanoidRootPart") if (badMob.Position - hrp.Position).magnitude < 100 then -- if badMob is less then 100 stoods away from player goodMob.Humanoid:MoveTo(badMob) -- this may be wrong, I dont have a lot of experience with MoveTo, you can use pathfinding service end end end
Here are some sources that you may find useful:
PathfindingService This can be used to help locate the hostile mobs. Locate their positions and chase after them.
Remember to equip your NPCs with weapons!
Magnitude This can be used to locate the nearest mob.
I've never tried clone simulator, but I think you clone the NPCs to help defend you? if so, check out Clone
If you want your NPCs to have animations, check out How to make Animations in Roblox Studio!