local players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local char = script.Parent
local head = char:FindFirstChild("Head")
local UpperTorso = char:FindFirstChild("UpperTorso")
local hrp = char:FindFirstChild("HumanoidRootPart")
local neck = head:FindFirstChild("Neck")
local Waist = UpperTorso:FindFirstChild("Waist")
local function getClosestPlayerHrp(dist)
local closestHrp = nil
for i, v in pairs(players:GetPlayers()) do
local tmpChar = v.Character or v.CharacterAdded:Wait()
if tmpChar then
local tmpHrp = tmpChar:FindFirstChild("HumanoidRootPart")
if hrp and tmpHrp then
local tmpDist = (tmpHrp.Position - hrp.Position).Magnitude
if tmpDist < dist then
closestHrp = tmpHrp
dist = tmpDist
end
end
return closestHrp, dist
end
end
end
while true do
local closestHrp, dist = getClosestPlayerHrp(50)
if closestHrp and hrp then
local dir = (closestHrp.Position - hrp.Position).Unit
local vecA = Vector2.new(hrp.CFrame.LookVector.X, hrp.CFrame.LookVector.Z)
local vecB = Vector2.new(dir.X, dir.Z)
local dotValue = vecA:Dot(vecB)
local crossValue = vecA:Cross(vecB)
local ht = hrp.Position.Y - closestHrp.Position.Y
local upAngle = math.atan(ht/dist)
local angle = math.atan2(crossValue, dotValue)
if angle > math.pi/3 then
angle = math.pi/3
end
if angle < -math.pi/3 then
angle = -math.pi/3
end
if Waist then
local xOffSet = Waist.C0.X
local yOffSet = Waist.C0.Y
local zOffSet = Waist.C0.Z
TweenService:Create(Waist, TweenInfo.new(0.5), {
C0 = CFrame.new(xOffSet, yOffSet, zOffSet) * CFrame.Angles(0, -angle/4, 0) * CFrame.Angles(-upAngle/2, 0, 0),
}):Play()
else
return CFrame.new()
end
if neck then
local xOffSet = neck.C0.X
local yOffSet = neck.C0.Y
local zOffSet = neck.C0.Z
TweenService:Create(neck, TweenInfo.new(0.5), {
C0 = CFrame.new(xOffSet, yOffSet, zOffSet) * CFrame.Angles(0, -angle/1.25, 0) * CFrame.Angles(-upAngle/2, 0, 0),
}):Play()
else
return CFrame.new()
end
end
wait()
end
We have no idea what it is you want?
Please try and follow the guide shown every time you create a post, and include:
- What is meant to happen
- What actually happens
- Any context that’s relevant
1 Like