[HELP] Making a command to force skin change

Hi everyone, I’m kinda new to developing in ESX and I wanted to make a command on which I can force players to change their skin using the openSaveableMenu function in esx_skin

This is the /skin command that already exists in esx_skin:

TriggerEvent(‘es:addGroupCommand’, ‘skin’, ‘admin’, function(source, args, user)
TriggerClientEvent(‘esx_skin:openSaveableMenu’, source)
end, function(source, args, user)
TriggerClientEvent(‘chat:addMessage’, source, { args = { ‘^1SYSTEM’, ‘Insufficient Permissions.’ } })
end, {help = _U(‘skin’)})

I tried copying the command and made something right here but it doesn’t work. The targeted player does not get the skin menu

TriggerEvent('es:addGroupCommand', 'forceskin', 'admin', function(source, args, user)
	local _source = source
	local target = tonumber(args[1])
	local xPlayer = ESX.GetPlayerFromId(target)
	
	if target and xPlayer ~= nil then
		TriggerClientEvent('esx_skin:openSaveableMenu', xPlayer)
	else
		TriggerClientEvent('chatMessage', _source, "SYSTEM:", {255, 0, 0}, "Invalid arguments.")
		return
	end
end, function(source, args, user)
	TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = '/forceskin (ID) - Force someone to change his skin'})

I have also been looking for this have you got it?

Won’t this only work if target == 1 (or true)?

xPlayer is already dependent on target, so having only if xPlayer ~= nil then should work the same way. You might want to print(tostring(xPlayer)) before sending the client event, to make sure that you got the correct ID.

Could you create one and send it?

Just change this line:
TriggerClientEvent('esx_skin:openSaveableMenu', xPlayer)
to
TriggerClientEvent('esx_skin:openSaveableMenu', target)

Any way for Legacy ESX?

not working :C u can fix??

any way for legacy?

it’s work !!