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

Unable to cast CoordinateFrame to Vector3 please help?

Asked by
Memotag 226 Moderation Voter
6 years ago

The idea of the script is to clone a model from 'ReplicatedStorage', take it to the Workspace and then place it in the same position as a baseplate. Right now the script will do everything as explained but it will also output the error ' Unable to cast CoordinateFrame to Vector3' and I have no idea on how to fix it.

Yes I am completely aware of deprecated parts of the script, I just want this issue solved.

Here is the code:

wait(1)
model = game.ReplicatedStorage.Tycoon1
floor = script.Parent.Floor
backup = model:Clone()
backup.Parent = game.Workspace
wait(0.1)
backup:MoveTo(CFrame.new(floor.Position))

function Regen() 
model:remove()
wait(1) 
model = backup:clone() 
model.Parent = script.Parent  
model:makeJoints() 
end

while true do 
wait(1.5) 
if backup.Main.Owner.Value ~= "" then 
if not game.Players:FindFirstChild(backup.Main.Owner.Value) then 
Regen() 

end 
end 
end 

Any help is appreciated!

1 answer

Log in to vote
0
Answered by 6 years ago

This is because the argument to MoveTo is a Vector3, not a CFrame. However, you should be using SetPrimaryPartCFrame instead. Make sure a PrimaryPart is set, and use the method.

wait(1)
local model = game.ReplicatedStorage.Tycoon1
local floor = script.Parent.Floor
local backup = model:Clone()
backup.Parent = game.Workspace
wait(0.1)
backup:SetPrimaryPartCFrame(CFrame.new(floor.Position))

local function Regen() 
    model:Destroy() -- remove is deprecated use Destry
    wait(1) 
    model = backup:Clone()  -- clone is deprecated
    model.Parent = script.Parent  
    model:MakeJoints() -- makeJoints deprecated
end

while true do 
    wait(1.5) 

    if backup.Main.Owner.Value ~= "" then 
        if not game.Players:FindFirstChild(backup.Main.Owner.Value) then 
            Regen() 

        end 
    end 
end 

On a side note, clone, makeJoints, and remove are deprecated, use Clone, MakeJoints, and Destroy instead.

0
Thank you for the help. Now I get 'Model:SetPrimaryCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.' on Line 7 after making the changes. Any suggestions? Memotag 226 — 6y
0
I clearly stated to set a PrimaryPart before using the method. Set a PrimaryPart. User#19524 175 — 6y
Ad

Answer this question