Jump to content

bad arg @ destroyElement


pa3ck

Recommended Posts

Posted

I dont know if this will help you, but after "destroyElement(helmet[lp])" do "helmet[lp] = nil", also from this part of code, I cant see who is "lp" and who is "thePlayer"

Posted

Thanks for reply, thePlayer was triggered from client side (so thePlayer = getLocalPlayer()). The problem is, that it wont destroy the element at all. I'll try what you said.

Posted

You should then try with helmet[thePlayer] instead of helmet[lp] :)

EDIT: Try this:

helmet = {} 
--lp = getElementType(thePlayer) 
if getElementData(thePlayer, 'helmetOn') ~= 1 then 
    setElementData(thePlayer, 'helmetOn', 1) 
    local x, y, z = getElementPosition(thePlayer) 
    helmet[thePlayer] = createObject(2053, x, y, z) 
    setObjectScale(helmet[thePlayer], 2.4) 
    exports.bone_attach:attachElementToBone(helmet[thePlayer],thePlayer,1,0,0.03,0.1,0,0,180) 
else 
    setElementData(thePlayer, 'helmetOn', 0) 
    destroyElement(helmet[thePlayer]) 
    helmet[thePlayer] = nil 
end 

Posted

Thanks for you help, this was my first try, but it gave me the same error. Now I copy-pasted your code and give the same error. Bad argument @ destroyElement

Posted

The event is triggered when you click on a gui, and 'thePlayer' is sent from client side to server side. So its defined client side as getLocalPlayer()

Posted

oh also you don't need the element data, you can use the table.

something like:

if not isElement(helmet[thePlayer]) then 
-- create it 
else 
-- destroy it 
end 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...