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

when i use :SetPrimaryPartCFrame() Unable to cast double to CoordinateFrame comes up in output?

Asked by 6 years ago

Well here is the segment of my script where i need to move the whole model

script.Parent.Touched:connect(function(hit)
    if hit.Name == ("Win") then
        script.Parent.Parent:SetPrimaryPartCFrame(1,1,1)
        wait(0.3)
    end
end)

then when character(the name of the model) touches "win" Unable to cast double to CoordinateFrame comes up in output and i dont understand why. Thank you for you help

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You need a CFrame (CoordinateFrame), not just 3 parameters. It is like how you cannot move a part like this

workspace.Part.Position = 1, 10, 1

but instead, you have to do

workspace.Part.Position = Vector3.new(1, 10, 1)

Now, for a CFrame, you would do

script.Parent.Touched:connect(function(hit)
    if hit.Name == ("Win") then
        script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(1,1,1))
        --The wait is unnecessary, as it does nothing.
    end
end)

Also, read my bio and do what it says. Don't indent with spaces.

Ad
Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago

The reason this error is occuring is because the funcition SetPrimaryPartCFrame() requires a CFrame to be given, you are giving it (1,1,1) which is just numbers. To fix this we need to give it a CFrame()

script.Parent.Touched:connect(function(hit)
    if hit.Name == ("Win") then
        script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(1,1,1)) --Notice how im giving it a cframe
        wait(0.3)
    end
end)

Answer this question