[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?

1 Like

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?

any way for legacy?

1 Like

it’s work !!

passed the updated code that worked for me (sorry for my English)

ESX.RegisterCommand('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
		xPlayer.triggerEvent('esx_skin:openSaveableMenu')
	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, false, {help = '/forceskin (ID) - Force someone to change his skin'})
4 Likes

Thank you!

HELP!!! for me the /skin command is (out of a sudden) not working anymore… it really freaks me out - somebody any ideas?

1 Like

where does this go

1 Like

this works perfectly appreciate it!

in esx_skin then the server folder and in main.lua

does it matter where i put it?