Hey guys, I used this pre made 3Dtext function in my client.lua to make it create an text above the players head with a command. It all worked just fine. Now is the problm that only the client can see it so I need to put it to my server.lua but those natives from the clientside does not exist on server side. Is there a way to do it easy? I am developing since 2022 in fivem lua and cant figure it out, thank you for your help!
(Sorry for my english ^ ^)
EDIT:

I assume the flow you are trying to describe is:
Client 1 runs command > All clients see a message above Client 1’s head
and what you are describing as happening is:
Client 1 runs command > Client 1 sees message above Client 1’s head
The DrawText native and its SetText options are all client side only natives, the server can’t draw text, it has no graphics display for the instance of the game it is running.
What you need to do is trigger a server event after Client 1 runs the command, and that server event needs to tell every client to draw the text above Client 1’s head.
Client-side
local playerTexts = {}
local distance = 20.0 -- Max distance to drawtext
function DrawTextFunction(...)
-- do drawtext
end
CreateThread(function()
while true do
Wait(1)
if #playerTexts > 0 then
local coords = GetEntityCoords(PlayerPedId())
for _,info in pairs(playerTexts) do
local textCoords = info.coords
if #(textCoords - coords) < distance then
DrawTextFunction(info.coords,info.text,info.color)
end
end
else
Wait(500)
end
end
end)
RegisterNetEvent("drawText:addNewText")
AddEventHandler("drawText:addNewText", function(info)
table.insert(playerTexts, info)
end)
RegisterCommand("drawtext", function(source,args,raw)
local text = args[1]
local coords = args[2]
local color = args[3]
--more stuff..
TriggerServerEvent("drawText:newText", text, coords, color)
end)
Server-side
RegisterServerEvent("drawText:newText")
AddEventHandler("drawText:newText", function(text, coords, color, --[[..more stuff]])
local player = source
TriggerClientEvent("drawText:addNewText", -1, {text = text, coords = coords, color = color})
end)
This code should help you. It’s a really bad example and you should secure it or use it differently, but it’s what you need.
Hey , first of all, thank you all for your help! I will try out your code thank you. I dont really undersand the „for loop“ thing. Could you may explain your client side?