SetPlayerModel command does nothing

I’m trying to make a /cop command that simply changes the skin to a cop skin and prints “You are now an officer”, tried to follow a few examples yet it only prints the message and does not change the skin.

This is my code:

RegisterCommand('Cop', function(source,args)

PlayerId = GetPlayerPed(-1)
local model = GetHashKey('s_f_y_cop_01')
RequestModel(model)
while not HasModelLoaded do
 Wait(500)
end
SetPlayerModel(PlayerId, model)
SetModelAsNoLongerNeeded(model)
TriggerEvent('chat:addMessage', {args = {"You are now a police officer"}})


end, false)

Thanks in advanced.

1 Like

Seems like you missed some bits and pieces.

PlayerId = GetPlayerPed(-1)

Not sure if this works, Lua might actually store it as a global value, since local is not used.

while not HasModelLoaded do

HasModelLoaded requires the model that it wants to check against, again, lua just presumes this is some sort of value and immediately exits that while loop.

Try this code:

RegisterCommand('cop', function(source,args)
    local player = PlayerPedId()
    local model = GetHashKey('s_f_y_cop_01')

    RequestModel(model)
    while not HasModelLoaded(model) do
        Wait(100)
    end

    SetPlayerModel(player, model)
    SetModelAsNoLongerNeeded(model)
    
    TriggerEvent('chat:addMessage', {args = {"You are now a police officer"}})
end, false)

Thank you for the comment, but it still isn’t working, and I found out something even weirder, if the letter “c” on the word ‘cop’ at the first line isn’t capitalized, it won’t even trigget the chat message saying “you are now a police officer”.

Hi,

For SetPlayerModel you need to pass the player Id not the ped, you should use PlayerId() instead of PlayerPedId()

This work for me:

RegisterCommand('cop', function(source,args)
    local player = PlayerId()
    local model = GetHashKey('s_f_y_cop_01')

    RequestModel(model)
    while not HasModelLoaded(model) do
        Wait(100)
    end

    SetPlayerModel(player, model)
    SetModelAsNoLongerNeeded(model)

    TriggerEvent('chat:addMessage', {args = {"You are now a police officer"}})
end, false)
1 Like

Thanks!