Hello, after testing hours and hours I give up… What is wrong with my code? The Problem is that it teleport always to new Humanoids and then my fixed BodyGyro go away… So I was trying that both always run at same time:
local rootPart = game.Players.LocalPlayer.Character.HumanoidRootPart
local human = game.Players.LocalPlayer.Character.Humanoid
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
while true do
function findTarget()
local dist = 100000
local target = nil
local BodyGyro = Instance.new("BodyGyro")
local pos = Vector3.new(0, 0, 0)
local lookAt = Vector3.new(0, -256, 0)
for i,v in pairs(game.Workspace.dungeon:GetDescendants()) do
local humanoid = v:FindFirstChild("Humanoid")
local head = v:FindFirstChild("Head")
if humanoid or head then
if (head.Position - rootPart.Position).magnitude < dist then
dist = (head.Position - rootPart.Position).magnitude
target = head
end
end
end
return target
end
end
while wait(3) do
local head = findTarget()
rootPart.BodyGyro.CFrame = CFrame.new(pos, lookAt, head.Position)
wait(1)
game:GetService("Players").LocalPlayer.Character.Humanoid.HipHeight = 10
wait(10)
end
wait(4)
