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

Can someone give me some code for an npc to attack the nearest player?

Asked by
Hifived 10
2 years ago

im making a game and need attack script for an r6 npc i have everything like the movement finished but now i need some attack script please someone tell me how to make some.

0
For next time make sure to not ask for hand outs, this is helping site, not for free scripts. Sabailuridze 126 — 2y

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago

To find the nearest you can do a Magnitude check with the target

local Target = Workspace.Enemy.PrimaryPart --Example
local YourPosition = Script.Parent.PrimaryPart
local Distance = (Target.Position-YourPosition.Position).Magnitude
if Distance < 50 then --near the target by 50
    Print("You are near the target")
end
0
how do i make it attack though? Hifived 10 — 2y
0
well you have to do it your self with a function or other methods Puppynniko 1059 — 2y
0
ok Hifived 10 — 2y
Ad

Answer this question