Hello!
BACKGROUND:
I have a string value called ‘BoatType’. My game is about boats. This value is used to store the name of the kind of boat the player is using. Whenever a change is detected in this value, a script will look through a folder in the ReplicatedStorage which lists all types of boats in the game, and check that the new value is an existing boat and will replace the boat in a ViewportFrame with the boat model of their Boat Type. (E.g, BoatType changes to ‘Happy Home’, Default Boat in the ViewportFrame is deleted, Happy Home model is cloned and put into the ViewportFrame) If the user unequips their current boat, the boat model is deleted and the default boat is cloned to ViewportFrame.
PROBLEM:
For some reason, the Happy Home model appears with multiple bricks missing when it’s loaded. However, when I clone the model and place it in workspace, it’s fine. When I change the model back to default when no BoatType is equipped, the default boat also loads fine and is not missing bricks.
Default Boat model in ViewportFrame - before BoatType value change
Happy Home model in ViewportFrame - after BoatType value is changed to “Happy Home”
If you would like to look at the code:
local ViewportFrame = BoatsFrame.ViewportFrame
function BoatTypeChanged()
if BoatType.Value ~= "" then --if the default boat isn't being equipped and player has a different boat
local BoatTypeExists = game.ReplicatedStorage.TotalItems.BoatTypes:FindFirstChild(BoatType.Value)
if BoatTypeExists then --verify they are using an existing boat
local BoatModel = BoatTypeExists:FindFirstChild("BoatModel"):Clone() --clone the model
ViewportFrame.Boat:Destroy() --remove existing
BoatModel.Name = "Boat"
BoatModel.Parent = ViewportFrame
BoatModel:MoveTo(game.ReplicatedStorage.Info.ViewportBoatPos.Value) --Moves boat to the position to get it in frame
end
else
ViewportFrame.Boat:Destroy() --destroys old boat
local NewBoat = game.ReplicatedStorage.Info.ViewportBoat:Clone() --ViewportBoat is default boat
NewBoat.Parent = ViewportFrame --replaces with default bus
NewBoat.Name = "Boat"
end
This has been bugging me for a while. I hope someone can help. Thanks!