So I have code here that is supposed to change the CFrame of a copied object to the location of the previous object that was destroyed. When I print the last objects position , it prints the correct location but when I set the CFrame to the same PRINTED position, its position isnt set to the correct position. Sorry if my English is not good, It isn’t my MAIN language.
here is my code that is placed in ServerScriptService:
local repStor = game:GetService("ReplicatedStorage")
local main = game:GetService("ReplicatedStorage"):FindFirstChild("wheat-2")
local localPosX = main:GetModelCFrame().X
local localPosY = main:GetModelCFrame().Y
local localPosZ = main:GetModelCFrame().Z
main.AncestryChanged:Connect(function(child: Instance, parent: Instance)
if child == main then
print("Checkpoint 1 Conf")
if parent == game.Workspace then
wait(2)
main:Destroy()
local wheat3Copy = repStor:FindFirstChild("wheat-3")
wheat3Copy:SetPrimaryPartCFrame(CFrame.new(localPosX, localPosY, localPosZ))
wheat3Copy.Parent = game.Workspace
end
end
end)