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

How do I make NPCS defend you from hostile mobs?

Asked by 3 years ago

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?

2 answers

Log in to vote
0
Answered by 3 years ago

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
0
I am relatively new to scripting, please mind that BeautifulAuraLover 371 — 3y
0
Never mind, It didn't work do u got any Ideas that It may work? (I unanchor It but It didn't work maybe Its the npc attack script I dunno) imnotaguest1121 362 — 3y
Ad
Log in to vote
1
Answered by 3 years ago

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!

0
Thanks man!, I will try thanks I'll tell you If It didn't work or not imnotaguest1121 362 — 3y

Answer this question