scolen Posted August 27, 2023 Share Posted August 27, 2023 When one of these markers is hit, another marker is destroyed. After that, even if other markers are hit, none of the markers will be destroyed. What is the reason for it ? garbages = { {-1881.14380, -1707.47888, 21.75000}, {-1885.83081, -1723.84656, 21.75641}, {-1896.03723, -1731.46301, 21.75000}, {-1908.80933, -1733.61536, 21.75000} } function pickup(player) for i,garbage in pairs(garbages) do marker = createMarker(garbage[1], garbage[2], garbage[3], "cylinder", 3.0) function picked(player) destroyElement(marker) end addEventHandler("onMarkerHit", marker, picked) end end Link to comment
Rougue90 Posted August 27, 2023 Share Posted August 27, 2023 (edited) I believe that is because you have been destroying variable marker, and not the source of onMarketrHit. So every time you hit any cylinder, the code will destroy the last cylinder in variable marker Try this one to destroy do source of hit garbages = { {-1881.14380, -1707.47888, 21.75000}, {-1885.83081, -1723.84656, 21.75641}, {-1896.03723, -1731.46301, 21.75000}, {-1908.80933, -1733.61536, 21.75000} } function pickup(player) for i,garbage in pairs(garbages) do marker = createMarker(garbage[1], garbage[2], garbage[3], "cylinder", 3.0) function picked(player) destroyElement(source) -- here the modification end addEventHandler("onMarkerHit", marker, picked) end end If it helped, pls give rep+. Edited August 27, 2023 by Rougue90 1 Link to comment
scolen Posted August 28, 2023 Author Share Posted August 28, 2023 17 hours ago, Rougue90 said: I believe that is because you have been destroying variable marker, and not the source of onMarketrHit. So every time you hit any cylinder, the code will destroy the last cylinder in variable marker Try this one to destroy do source of hit garbages = { {-1881.14380, -1707.47888, 21.75000}, {-1885.83081, -1723.84656, 21.75641}, {-1896.03723, -1731.46301, 21.75000}, {-1908.80933, -1733.61536, 21.75000} } function pickup(player) for i,garbage in pairs(garbages) do marker = createMarker(garbage[1], garbage[2], garbage[3], "cylinder", 3.0) function picked(player) destroyElement(source) -- here the modification end addEventHandler("onMarkerHit", marker, picked) end end If it helped, pls give rep+. thanks bro Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now