I’m trying to load a tool using LoadAsset (Script, no LocalScript) and in Studio it work perfectly, but when I publish my game it will not work. “Tool not loaded-” doesn’t even appear in the console. This is the code:
local MarketplaceService = game:GetService("MarketplaceService")
local InsertService = game:GetService("InsertService")
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 17460799) or IsAdministrator(Player) then
local Success, BoomBox = pcall(InsertService.LoadAsset, InsertService, 6760000416)
if Success and BoomBox then
local Tool = BoomBox:FindFirstChildWhichIsA("Tool"):Clone()
Tool.Parent = Player.Backpack
else
print("Tool not loaded.")
end
end
Thank you.
There might be an error in your pcall that won’t show up in your output, because that is what pcall does. Try adding this before your if statement, it might help you understand what happened:
print(Success, Boombox)
I’ve added the pcall after several attempts, unfortunately in vain.
I tried to print in case Success was false, however nothing will print in the console.
Perhaps this if statement didn’t go through, then?
The condition is successful because if I try this script on Roblox Studio it will work without problems while in the game it will not work. I own the gamepass and I’m also an administrator so both conditions will always be true. Also I’m the creator of the game and the required model.
Is the code wrapped in anything? Like is this code in a function of an event?
I think the answer is fairly simple.
I’m pretty sure you can only load assets that you own directly. Such as with animations. They work in studio, but not in game. Obtain the asset within the inventory, or the inventory of the owner of the game, and then it should work.
The code is inside a function called LoadGamepass(Player). This is the piece of code:
game:GetService("Players").PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function()
LoadGamepass(Player)
end)
...
end)
Just looked at the API Reference: Definitely the answer. No coding problem.
“An asset loaded by this function must be created or owned by either the game creator or Roblox. Additionally, benign asset types such as t-shirts, shirts, pants and avatar accessories are loadable from any game as they are public.”
I am the owner of the asset, the gamepass and the game as well.
Try putting a print statement before the if statement so we know that CharacterAdded is running properly.
Is the game by any chance owned by a group you own?
1 Like
Here comes the debugging problem: the print from server scripts on the game are not visible in the console. However on Roblox Studio the print works and loads the desired resource, in the game it does not.
Already tried and does not print anything. I tried to put print also at the beginning and at the end of the script and it doesn’t work anyway.
Client:
Studio:
I’ve uninstalled and reinstalled Roblox and Roblox Studio and now work. Strange bug. Anyway I’ve solved. Thank you for your time.
1 Like