How can I delete an Object that already exist?

I’m trying to delete “prop_rub_binbag_03” this object,
This Object is created by default.

I tried:
SetEntityAsMissionEntity(GetHashKey(“prop_rub_binbag_03”), true, true)
SetEntityAsMissionEntity(“prop_rub_binbag_03”, true, true)
DeleteEntity(GetHashKey(“prop_rub_binbag_03”))
DeleteEntity(“prop_rub_binbag_03”)

I’m probably using it wrong.

Thanks for your help

Can you explain what exactly you want to do?

do you want to delete an object from all the map or from one place?

No, I have this object that placed around the map, it was created by the server, if a player click E then it
will do something and the object will be deleted.

I couldn’t make it delete this object

You can try use this native: GET_CLOSEST_OBJECT_OF_TYPE - Cfx.re Docs

Get the object in-game, then delete it.

I tried this is not working

Get the object, set it as MissionEntity, set it as NoLongerNeeded (all native stuff) and then you should be able to delete it.

can you send code example?

local obj = GetClosestObjectOfType(coords.x, coords.y, coords.z, 3.0, GetHashKey("prop_rub_binbag_03"), false, false, false)
if DoesEntityExist(obj) then
   NetworkRequestControlOfEntity(obj)
   SetEntityAsMissionEntity(obj)
   DeleteObject(obj)
else
  print("cannot find the obj")
end

At the coords you can either put predefined coords for the props on the map or you can take the player’s coords.
Try this and see if it works :slight_smile: