Replace model: SetPrimaryPartCFrame / GetPrimaryPartCFrame

I have a model in a scene that I’d like the user to click on to replace with another model. I’ve got the code working… however, when I SetPrimaryPartCFrame on the new model with the value returned from GetPrimaryPartCFrame, the new model does NOT get positioned where the old model was.

What the heck am I missing?

Thanks.

1 Like

Hi. That can be due to many reasons. Please give your code. And a screenshoot of your models (with primary part visible in a special color, that I can see them)

2 Likes

Here’s the code… I pass in the tower I wish to replace and a string that represents the new model that I wish to create and replace it with:


function UpgradeTower( tower, newTowerType )
print("Upgrade ", newTowerType)
local currentPosition = towerSelectedForUpgrade:GetPrimaryPartCFrame()
local newTower = CreateTowerUpgrade( newTowerType )
if newTower ~= nil then
tower:SetPrimaryPartCFrame( currentPosition )
towerSelectedForUpgrade:Destroy()
towerSelectedForUpgrade = nil
end
end

This first image just shows both models with the primary part in red.
The second and third images show the model on the map before they are replaced.
The fourth and fifth images show the model replaced. You can see that the new model is not where it should be!


3


1 Like

Duh… I found the error. I/O error.
tower:SetPrimaryPartCFrame( currentPosition )
Should be
newTower:SetPrimaryPartCFrame( currentPosition )

Ok, nice. Sorry for don’t reply before. It’s cool if you found the solution by yourself. Please make this topic “solved”.

NP. Sometimes, a clear head shows the problem!

1 Like