Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local localPlayer = Players.LocalPlayer
- local character
- local humanoid
- local humanoidRootPart
- -- Función para verificar si el jugador tiene un ítem
- local function playerHasItems(player)
- local character = player.Character
- if not character then return false end
- if character:FindFirstChildOfClass("Tool") then
- return true
- end
- local backpack = player:FindFirstChildOfClass("Backpack")
- if backpack and #backpack:GetChildren() > 0 then
- return true
- end
- return false
- end
- -- Función para obtener el jugador más cercano
- local function getClosestPlayer()
- local closestPlayer = nil
- local shortestDistance = math.huge
- for _, player in ipairs(Players:GetPlayers()) do
- if player ~= localPlayer then
- local targetCharacter = player.Character
- if targetCharacter then
- local targetHumanoidRootPart = targetCharacter:FindFirstChild("HumanoidRootPart")
- if targetHumanoidRootPart then
- local distance = (humanoidRootPart.Position - targetHumanoidRootPart.Position).Magnitude
- if distance < shortestDistance then
- shortestDistance = distance
- closestPlayer = player
- end
- end
- end
- end
- end
- return closestPlayer
- end
- -- Función para hacer que el personaje mire al humanoide más cercano
- local function lookAtClosestPlayer()
- if not _G.EnableLookatplayerclosset then return end -- Verificar si la funcionalidad está habilitada
- local closestPlayer = getClosestPlayer()
- if closestPlayer and playerHasItems(localPlayer) then
- local targetCharacter = closestPlayer.Character
- if targetCharacter then
- local targetHumanoidRootPart = targetCharacter:FindFirstChild("HumanoidRootPart")
- if targetHumanoidRootPart then
- local direction = (targetHumanoidRootPart.Position - humanoidRootPart.Position).unit
- humanoidRootPart.CFrame = CFrame.lookAt(humanoidRootPart.Position, humanoidRootPart.Position + direction)
- end
- end
- end
- end
- -- Función para reiniciar el seguimiento de la mirada al respawn
- local function onCharacterAdded(characterInstance)
- character = characterInstance
- humanoid = character:WaitForChild("Humanoid")
- humanoidRootPart = character:WaitForChild("HumanoidRootPart")
- -- Actualizar continuamente la dirección de la mirada
- RunService.Heartbeat:Connect(function()
- if _G.EnableLookatplayerclosset and playerHasItems(localPlayer) then
- lookAtClosestPlayer()
- end
- end)
- end
- -- Asegurar que el código se reinicie correctamente después de cada respawn
- localPlayer.CharacterAdded:Connect(onCharacterAdded)
- -- Si el jugador ya tiene un personaje, conectar de inmediato
- if localPlayer.Character then
- onCharacterAdded(localPlayer.Character)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement