local x,y,z = getElementPosition(localPlayer)
local myPed = createPed(0, x, y+1, z)
setTimer(function()
setPedFollow(myPed, localPlayer)
end, 1000, 0)
function setPedFollow(theElement, theTarget)
if theElement then
local x, y, z = getElementPosition(theTarget)
local rx, ry, rz = getElementRotation(theTarget)
local ex, ey, ez = getElementPosition(theElement)
local distance = getDistanceBetweenPoints3D(x, y, z, ex, ey, ez)
local rotation = findRotation(ex, ey, x, y)
setPedRotation(theElement, rotation)
if distance > 2 then
setPedControlState(theElement, "forwards", true)
else
setPedControlState(theElement, "forwards", false)
end
end
end
function findRotation( x1, y1, x2, y2 )
local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) )
return t < 0 and t + 360 or t
end
try this also change script file type to client
if you don't have any other code in the file it works, i tested it