Error on InsertScript and Player Backpack

Hello how are you? I’m having problems with my code, it serves to load an item and put it in the player’s inventory

This is my code:

event = game.ReplicatedStorage.UiWorldEvent.GetIten
event.OnServerEvent:Connect(function(player, id)
	-- id is the item id
	local getservice = game:GetService("InsertService")
	local loaded = getservice:LoadAsset(tostring(id))
	local item = getservice:Insert(loaded)
	item.Parent = player.Backpack
end)

And when it runs, it resumes the following error:

 15:26:42.600  item ID is:116040828  -  Cliente - LocalScript:9
 
15:26:42.814  ServerScriptService.UIWorldEventsScript.itensgiver:7: attempt to index nil with 'Parent'
1 Like

InsertService:Insert is deprecated

1 Like

InsertService:Insert() doesn’t return an Instance, and it’s deprecated. Try to set the item’s parent directly from the loaded variable.

local loaded = getservice:LoadAsset(id)
loaded.Parent = player.Backpack
2 Likes


It worked, thanks :wink:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.