심플한 NPC를 만들고,
MoveTo를 이용해 가장 가까운 플레이어를 찾아서 따라다니는 Script 입니다.
local npcHumanoid = script.Parent.Humanoid
local npcHRP = script.Parent.HumanoidRootPart
local function GetNearestPlayer(minimumDistance)
local closestMagnitude = minimumDistance or math.huge
local closestPlayer
for i,v in next, game.Players:GetPlayers() do
local Character = v.Character
if (Character) then
local humanoid = Character.Humanoid
local HRP = Character.HumanoidRootPart
if (humanoid.Health > 0) then
local mag = (npcHRP.Position - HRP.Position).Magnitude
if (mag <= closestMagnitude) then
closestPlayer = v
closestMagnitude = mag
end
end
end
end
return closestPlayer
end
while true do
local player = GetNearestPlayer(3000)
if player then
print (player.Name)
npcHumanoid:MoveTo(player.Character.HumanoidRootPart.Position)
end
wait(2)
end
'Roblox Script' 카테고리의 다른 글
#14 : 닿으면 체력이 떨어지는 블록 (0) | 2020.08.06 |
---|---|
#12 : 총만들기 (인증 Weapons Kit 사용하기) (0) | 2020.08.06 |
#11 : 그룹에 따라 팀 나누기 (Team by Group) (0) | 2020.08.06 |
#10 : 플레이어 머리에 이름 표시 - Player Title (Team / Role) BillboardGui (0) | 2020.08.06 |
#9 : RemoteEvent로 Sever에서 local function 호출 (0) | 2020.08.06 |