Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

1 comment

0

For next time make sure to not ask for hand outs, this is helping site, not for free scripts.

1 answer

✓ Accepted answer

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

3 comments

0

how do i make it attack though?

0

well you have to do it your self with a function or other methods

0

ok

This discussion is preserved as it was. New answers, comments, and votes are closed.