I have this function I’m using to handle the case of Roblox failing to insert the model, since it’s very integral to the game. To handle it, it makes another request to load the asset after x amount of seconds if it failed to before.
The place this is being run in is a group place and the model is free.
The code works in test servers and in ‘Play Mode’, but doesn’t work in an actual server.
So far I’ve played around with no pcall (just throws an error on the LoadAsset line and with no message for what the error is except for giving the stack), and I’ve looked at half a dozen other questions related to LoadAsset as well as the wiki and none of these really help.
01 local function loadAssetUntilWorks(id, maxTries)
02 local model,success,message
03 local i = 0
04
05 --Sets the maxTries to -1 (making the loop infinite) if maxtries isn't
06 --specified or is less than 0
07 if not maxTries then
08 maxTries = -1
09 elseif maxTries < 0 then
10 maxTries = -1
11 end
12
13 print("Settings - maxTries: " .. maxTries)
14
15 --Makes sure the amount of tries isn't 0
16 if maxTries ~= 0 then
17 repeat
18 print("Settings - On try numbah " .. i)
19 --Keeps trying until successful and then returns the model
20
21 success,message = pcall(function()
22 model = InsertService:LoadAsset(id) --The problem line
23 end)
24 if success then
25 return model
26 else
27 i = i+1
28 warn("Whoopsie: " .. message)
29 wait(WAIT_TIME_BEFORE_SECOND_ATTEMPT)
30 end
31 until i==maxTries
32 else
33 return
34 end
35 end
It’s a model I made that’s free. I’m trying to insert it in a group place.
It works fine in Play mode and in a test server but doesn’t work in an actual server.
Alright, this certainly is weird. I attempted to insert several of your free models into my studio, I received “HTTP Error 403” - which basically is forbidden. I did this several times and I always got Error 403, then I took one took one of your models (clicked “Get”) - then when I tried with the model I just took, I received a Bad Request instead.
And I even tried again with models that I had not taken, and it gave me Bad request, where it just before I took the model had given me 403 errors.
EDIT: Okay, this must be a bug. Here’s what happened:
I opened Roblox Studio, and launched a command to get this model, I was met with 403 errors. I attempted to use InsertService multiple times
I went back to the browser and took the model (clicking “Get” etc.) - when I went back to studio to try to load it in again, I got a “Bad Request”.
I opened a new studio, and while having the model, I attempted to load it in again, I was met with 403 errors again
I closed the last Studio window, and opened a new one, now when I tried to use InsertService to load it in, it magically worked.
NEW EDIT: It appears to be due to caching. If you attempt to insert the model without taking it first, it won’t work. If you first tried without taking it, then it won’t work until you re-open studio. I haven’t dug into anything else.