Skip to content

Instantly share code, notes, and snippets.

@xThrasherrr
Last active March 3, 2026 21:21
Show Gist options
  • Select an option

  • Save xThrasherrr/4de95881c5c8b716c4d1b118c0950016 to your computer and use it in GitHub Desktop.

Select an option

Save xThrasherrr/4de95881c5c8b716c4d1b118c0950016 to your computer and use it in GitHub Desktop.
FiveM Client Script - Move player head to look at closest talking player
-- config values
local config = {
debug = true,
distance = 20 -- distance to check
}
-- variables
local lastTargetPlayer, lastDist = nil, 100
local function debugTxt(...)
if not config.debug then return end
lib.print.info(...)
end
local function playerDist(ped1, ped2)
local coords1 = GetEntityCoords(ped1)
local coords2 = GetEntityCoords(ped2)
local dist = #(coords1 - coords2)
return dist
end
CreateThread(function()
local sleep = 1000
while true do
local playerPed = cache.ped
local coords = GetEntityCoords(playerPed)
local nearbyPlayers = lib.getNearbyPlayers(coords, config.distance, false)
if not nearbyPlayers or not next(nearbyPlayers) then
sleep = 1000
else
sleep = 500
for i = 1, #nearbyPlayers do
local targetPed = nearbyPlayers[i].ped
local targetPlayer = nearbyPlayers[i].id
if NetworkIsPlayerActive(targetPlayer) and MumbleIsPlayerTalking(targetPlayer) and not IsPedShooting(playerPed) then
local dist = playerDist(playerPed, targetPed)
if (dist < lastDist) and (targetPlayer ~= lastTargetPlayer) then
TaskLookAtEntity(playerPed, targetPed, -1, 2048, 3)
lastDist = dist
lastTargetPlayer = targetPlayer
debugTxt(('Looking at %s'):format(GetPlayerName(targetPlayer)))
end
else
if lastTargetPlayer then
TaskClearLookAt(playerPed)
lastDist = 100
lastTargetPlayer = nil
debugTxt('Reset Head')
end
end
end
end
Wait(sleep)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment