Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

InsertService not inserting a model ingame?

Asked by 5 years ago

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.

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.

local function loadAssetUntilWorks(id, maxTries)
    local model,success,message
    local i = 0

    --Sets the maxTries to -1 (making the loop infinite) if maxtries isn't
    --specified or is less than 0
    if not maxTries then
        maxTries = -1
    elseif maxTries < 0 then
        maxTries = -1
    end

    print("Settings - maxTries: " .. maxTries)

    --Makes sure the amount of tries isn't 0
    if maxTries ~= 0 then
        repeat
            print("Settings - On try numbah " .. i)
            --Keeps trying until successful and then returns the model  

            success,message = pcall(function()
                model = InsertService:LoadAsset(id) --The problem line
            end)
            if success then
                return model
            else
                i = i+1
                warn("Whoopsie: " .. message)
                wait(WAIT_TIME_BEFORE_SECOND_ATTEMPT)
            end
        until i==maxTries
    else
        return
    end
end

!enter image description here

Answer this question