WorldModel automaticly destroying itself? - GUI

Hello!
I’m trying to parent a character object into a WorldModel but I get an error saying WorldModel is not a vaild member of ViewportFrame. I have also tryed putting a part in it but still no luck. I’ve looked all over the internet and cant seem to find anything.
image

I have just realized that when the game starts its still there but as soon as I put something in it, it destroys. Here is some of the code:

-- The viewport frame
local icon = script.Parent.icon
local function loadModel(model:Model)
	local newmodel = model:Clone()
-- Here is where I set the model to be parented with the WorldModel
	newmodel.Parent = icon.WorldModel
	return newmodel
end

local function showDialog(data)
    -- Some code here I wont be adding cuz its irrelevant

    -- This references to a model I have in ReplicatedStorage, a normal R15 model.
    local model = loadModel(data.StorageModel)
end

Thanks for all help!

I seemed to have fixed it by adding this extra check before the loading of the model:

local newmodel = model:Clone()
local worldModel
if icon:FindFirstChild("WorldModel") == nil then
	worldModel = Instance.new("WorldModel")
	worldModel.Parent = icon
else
	worldModel = icon.WorldModel
end
newmodel.Parent = worldModel
return newmodel

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