PeterP Posted January 31, 2023 Share Posted January 31, 2023 function addCapacete (source) local capacete1 = getElementData(source, "capaceteOn") if capacete1 then exports.pAttach:detach(capacete1) destroyElement(capacete1) setElementData(source, "capaceteOn", nil) else capacete1 = createObject(1873,0,0,0) setElementData(source, "capaceteOn", capacete1) exports.pAttach:attach(capacete1, source, 8, -0.02,0,0,0,0,-104.4) end end addEvent ( "onaddCapacete", true ) addEventHandler("onaddCapacete", getRootElement(), addCapacete) I'm getting an error: bad argument @ 'destroyElement' [expected element at argument 1] on line 5 why am I getting this error? Link to comment
Shady1 Posted January 31, 2023 Share Posted January 31, 2023 destroyElement for elements,If you want to delete element data, use removeElementData on server side Link to comment
PeterP Posted January 31, 2023 Author Share Posted January 31, 2023 But I'm trying to destroy the object that was once attached to the player, Link to comment
Addlibs Posted February 1, 2023 Share Posted February 1, 2023 (edited) if capacete1 then This checks whether a value is assigned to capacete1 (this value could be anything -- a string, number, userdata, coroutine, element, etc.), not whether it is a valid value for the purposes of your script. If the warning message you get says "expected element", it means you've passed it something that isn't an element (for instance, it could be a userdata reference to an element that's been destroyed by another script). A solution that gets rid of the warning is if isElement(capacete1) then Edited February 1, 2023 by Addlibs 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