How to only delete client object?

I have this code:

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(1)
		local playerPedPos = GetEntityCoords(GetPlayerPed(-1), true)
		local fishingRod = GetClosestObjectOfType(playerPedPos, 10.0, GetHashKey("prop_fishing_rod_01"), false, false, false)
		
		if (IsPedActiveInScenario(GetPlayerPed(-1)) == false) then
			SetEntityAsMissionEntity(fishingRod, 1, 1)
			DeleteEntity(fishingRod)
		end
	end
end)

What it does is this: when you begin fishing using task, a rod is given to the player. However, after the task is completed the rod just sits in the boat / water, so the above code is used to “clean up” any fishing rods near the player.

However, I tested this today with someone on my private server and this caused a problem: when he started the fishing job, I could see him fishing but his fishing rod was missing.

Same thing for me, he could see me fishing but no fishing rod… how would I go about fixing this?

2 Likes

You loop and delete "prop_fishing_rod_01" in a radius of 10.0 so there is a chance (high) that you are removing the fishing rod of your friend.

I use the same kind of script and here is what I do:

  • Find the fishing rod in a radius of 1.0 to avoid detecting the wrong prop
  • Start anim and loop until player as stopped fishing
  • When the player stops fishing, remove the fishing rod
1 Like

Also I think createobject has a networked parameter.

Yes. There is also this native https://runtime.fivem.net/doc/reference.html#_0xA53ED5520C07654A wich is used to sync an object on the network.
But here, it is the task the player does that create the fishing rod.

1 Like

What do you think does “GETCLOSEST” mean.
As long as there is a specific object this native will allways return the closest rod no matter how big the distance is.

Why loop it? After player’s rod is gone, it goes for the next nearest player’s rod…forever.
It shouldn’t need to loop in order to delete only 1 object, am I wrong?