Hello amirmahdi,
I assume that every player can have a blip attached to it which is stored in the "jobs:police" element data slot of the player element. I can see that it is a server-side script because you are using the setElementVisibleTo function. By "gone" you mean that the player has left the server, right? For any kind of "gone" relationship where an element is being destroyed and you have to clean up any associated that with the to-be-destroyed element, you should use the "onElementDestroy" server-side event handler. For example, you can clean up the blip like this:
addEventHandler("onElementDestroy", root,
function()
if (getElementType(source) == "player") then
local wanted_blip = getElementData(source, "jobs:police");
if (wanted_blip) then
destroyElement(wanted_blip);
removeElementData(source, "jobs:police");
end
end
end
);
Please make sure that you are not creating a second blip and overwritting the "jobs:police" element data with the element still present in your code. After all, you are not checking whether "jobs:police" element data is already set with a blip before creating and assigning a new one. Doing this the wrong way would create multiple blips that overlap the original one and you would not be able to easily destroy these extra and unnecessary ones.
Good luck! ?