Facebook
From Saylac, 1 Year ago, written in Lua.
Embed
Download Paste or View Raw
Hits: 4279
  1. local neck = workspace.Dummy.Head.Neck
  2. local NPC = workspace.Dummy
  3.  
  4. function getClosestPlayer()
  5.         local closest_player, closest_distance = nil, 30
  6.         for i, player in pairs(workspace:GetChildren()) do
  7.                 if player:FindFirstChild("Humanoid") and player ~= NPC then
  8.                         local distance = (NPC.PrimaryPart.Position - player.PrimaryPart.Position).Magnitude
  9.                         if distance < closest_distance then
  10.                                 closest_player = player
  11.                                 closest_distance = distance
  12.                         end
  13.                 end
  14.         end
  15.         return closest_player
  16. end
  17.  
  18. local cframe0 = neck.C0
  19. while true do
  20.         local player = getClosestPlayer()
  21.         if player then
  22.                 local is_in_front = NPC.PrimaryPart.CFrame:ToObjectSpace(player.PrimaryPart.CFrame).Z < 0
  23.                 if is_in_front then
  24.                         local unit = -(NPC.PrimaryPart.CFrame.p - player.PrimaryPart.Position).unit
  25.                         neck.C0 = cframe0 * CFrame.new(Vector3.new(0, 0, 0), unit)
  26.                 end
  27.         end
  28.         wait()
  29. end

Replies to Code rss

Title Name Language When
Re: Code Insensitive Porcupine lua 3 Months ago.
Re: Code Melodic Guinea Pig lua 4 Months ago.
Re: Code Gamboge Zebra lua 1 Year ago.
Script ne local Roblox_game03 lua 1 Year ago.
Re: Code Smelly Kitten lua 1 Year ago.