To see errors and warnings from your script, use /debugscript 3.
The problem here is you are parsing a resource element into triggerClientEvent where it expects a player.
function ShowImage (player)
The player here is a resource, because you have bound it to onResourceStart.
If you want to send this image to everyone on the server, use root as "sendTo" parameter.
triggerClientEvent ( root, "onClientGotImage", root, response )
I've made a few changes to it, see the comments here:
-- server
function ShowImage()
outputChatBox ( "event called, fetching image..." )
fetchRemote ( "https://img.icons8.com/cotton/2x/baby.png",
function ( response, error )
if error == 0 then
triggerClientEvent ( root, "onClientGotImage", resourceRoot, response ) -- Use resourceRoot as the source of the event
outputChatBox ( "data sucessfully send to the player" )
else
outputChatBox ( "error "..error.." when fetching image." )
end
end
)
end
addEventHandler("onResourceStart", resourceRoot, ShowImage) -- Use resourceRoot otherwise it triggers when any resource starts
-- client
local myTexture
addEvent( "onClientGotImage", true )
addEventHandler( "onClientGotImage", resourceRoot, -- resourceRoot as source
function( pixels )
outputChatBox ( "client: ok." )
if myTexture and isElement ( myTexture ) then
destroyElement( myTexture )
end
myTexture = dxCreateTexture( pixels )
end
)
addEventHandler("onClientRender", root,
function()
if myTexture then
local w,h = dxGetMaterialSize( myTexture )
dxDrawImage( 200, 100, w, h, myTexture )
end
end )
This code works for you on your local server, but you will run into issues doing this with other players, because they won't have loaded the clientside script before you send the image to them. Let me know if you need more explanation.