[HELP] how to trigger command?

so when i type /cash it gives me 1000 dollar but i just wanna make a thing that types /cash to the chat and give to player 1000 dollar
TriggerClientEvent("chatMessage", source, "/cash")
doesnt work i just wanna a thing that writes the command for the player

1 Like

You are looking to register a command, so use RegisterCommand. See https://docs.fivem.net/docs/scripting-manual/introduction/creating-your-first-script/#implementing-a-car-spawner for an example :slight_smile:

1 Like

no i just wanna make a thing that writes /cash to the chat and make it run the cash command
i registered command and it isnt working

1 Like

this works but only deposit event works it types /cash to the chat and doesnt trigger the command
server.lua:

RegisterServerEvent("depositEvent")
AddEventHandler("depositEvent", function()
    runned = 1 
    local s = source
    TriggerClientEvent("chatMessage", s, "/cash")
   
end)


RegisterCommand("cash", function(source)


 TriggerEvent('es:getPlayerFromId', source, function(user)
 -- Activate the money for the current player

  
   user.addMoney(1000)

 -- Send the player some information regarding the money
 TriggerClientEvent('chatMessage', source, "SYSTEM", {187, 235, 42}, "added " .. tonumber(1000) .. " dollars")
  end)
end)

client.lua:


Citizen.CreateThread(function()
      Citizen.Wait(3000)

TriggerServerEvent("cash")
      TriggerServerEvent('depositEvent')
      TriggerServerEvent('cash')
      --TriggerServerEvent("es:getPlayerFromId")
     -- TriggerServerEvent('es:playerLoaded')
     -- TriggerServerEvent('es:getPlayerFromId')
  end)


pls help me i just wanna run the cash when it is triggered in client.lua