Is it possible to use state bags on props?
when the player takes prop on his hands i trigger a server event to write the state bag, then when the player puts prop on the ground, from client i try to read the value written in the state bag by server
but i get this error: SCRIPT ERROR: Execution of native 000000009e35dab6 in script host failed: Tried to access invalid entity: 1794
Where’s the error?
Here is my code:
client:
local playerPed
local coord
local tg
RegisterCommand('pick_up', function()
playerPed = PlayerPedId()
coord = GetEntityCoords(playerPed)
tg = GetClosestObjectOfType(coord, 1.5, GetHashKey('prop_picnictable_01'))
if tg then
local animDict = 'anim@heists@box_carry@'
RequestAnimDict(animDict)
TaskPlayAnim(playerPed, "anim@heists@box_carry@", "idle", 3.0, 3.0, -1, 63, 0, 0, 0, 0)
Citizen.Wait(100)
AttachEntityToEntity(tg, playerPed, GetPedBoneIndex(playerPed, 28422), 0.0, -0.7, -0.6, 0.0, 0.0, 0.0, true, true, false, true, 1, true)
TriggerServerEvent('chailua_pickup:write_state_bag', tg)
end
end)
RegisterCommand('put_down', function()
if tg then
Citizen.Wait(200)
StopAnimTask(playerPed, 'anim@heists@box_carry@', 'idle', 1.0)
DetachEntity(tg)
SetEntityCoords(tg, GetOffsetFromEntityInWorldCoords(tg, 0, 0.2, 0))
PlaceObjectOnGroundProperly(tg)
print(Entity(tg).state.table_number)
end
end)
RegisterKeyMapping('pick_up', 'Pick Up', 'keyboard', 'F6')
RegisterKeyMapping('put_down', 'Put Down', 'keyboard', 'F7')
server:
RegisterNetEvent('chailua_pickup:write_state_bag', function(tg)
Entity(tg).state:set('table_number', 'T0001')
end)