Hi.
When you check the element-data, here 'if getElementData(Planta, "Planta") == true then', you have to use source instead of Planta.
On wiki, you can see source is the element that got clicked by the player.
Because now, you only always check the last created object's element-data.
Always make your variables local otherwise they become global variables, and most of times you don't want that... mostly on server-side.
In your case, I see why you didn't make it local, but it's a bad practise. You can't store multiple players' carried objects in one single variable... so you have to store them in a table.
Something like that:
local objectCarries = {} -- store carryed objects in this table
function PegarVaso( player )
local Px, Py, Pz = getElementPosition( player )
local Vaso = createObject( 2203, Px, Py, Pz )
objectCarries[player] = Vaso -- store: player carry this object
setPedAnimation( player, "CARRY", "crry_prtial", 4.1, true, true, true )
exports.pAttach:attach(Vaso, player, 1.7, 0, 0.4, 0.4, 90, 0, 0 )
end
addCommandHandler( "pegarvaso", PegarVaso )
function LargarVaso( player )
local Px, Py, Pz = getElementPosition( player )
setPedAnimation( player, "CARRY", "putdwn", 1.0, false, false, false, true )
setTimer(function()
setPedAnimation( player )
if objectCarries[player] and isElement(objectCarries[player]) then -- is player carrying an object?
destroyElement( objectCarries[player] ) -- yes... so destroy it
objectCarries[player] = nil -- and don't forget to remove it from our table too
end
local Planta = createObject( 2203, Px , Py , Pz -0.85)
setElementData( Planta, "Planta", true )
end, 1200, 1)
end
addCommandHandler( "soltarvaso", LargarVaso )
function Planta( button, state, player ) -- Add the function
if button == "left" and state == "down" then
if getElementData(source, "Planta") == true then
triggerClientEvent( "MenuPlantar", player )
end
end
end
addEventHandler( "onElementClicked", root, Planta )
... and one more thing, source is a hidden variable what MTA define for you in most of times. Don't call your variables as source because you overwrite the hidden one... and can cause other problems.