I can’t really find what’s wrong here as I am getting no feedback, I type the command and it doesn’t return anything but doesn’t work either.
Client-Side
RegisterNetEvent('ac:car')
AddEventHandler('ac:car', function(args)
local vehicleName = args[1]
if not IsModelInCdimage(vehicleName) or not IsModelAVehicle(vehicleName) then
TriggerEvent('chat:addMessage', {
args = { 'It might have been a good thing that you tried to spawn a ' .. vehicleName .. '. Who even wants their spawning to actually ^*succeed?' }
})
return
end
RequestModel(vehicleName)
while not HasModelLoaded(vehicleName) do
Wait(500) -- often you'll also see Citizen.Wait
end
local playerPed = PlayerPedId() -- get the local player ped
local pos = GetEntityCoords(playerPed) -- get the position of the local player ped
local vehicle = CreateVehicle(vehicleName, pos.x, pos.y, pos.z, GetEntityHeading(playerPed), true, false)
SetPedIntoVehicle(playerPed, vehicle, -1)
SetEntityAsNoLongerNeeded(vehicle)
SetModelAsNoLongerNeeded(vehicleName)
TriggerEvent('chat:addMessage', {
args = { 'You spawned ^*' .. vehicleName .. '!' }
})
end)
Server-Side
RegisterCommand('car', function(source, args, rawCommand)
if IsPlayerAceAllowed(source, "admincommands") then
TriggerClientEvent('ac:car', args[1], args)
else
print("You're not an admin.")
end
end)