Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

? invalid argument #1 to 'new' (Vector3 expected, got CFrame)

I've read other stuff similar to my question, none really helped me though

local TS = game:GetService("TweenService")
local Plr = game:GetService("Players").LocalPlayer
local HRP = Plr.Character.HumanoidRootPart

if success() then
    for _, v in pairs(workspace:GetChildren()) do
        for _, c in pairs(v:GetChildren()) do
            if c:IsA("Tool") then
                TS:Create(HRP, TweenInfo.new(1), {CFrame = CFrame.new(c:FindFirstChild("Handle").CFrame)})
                task.wait(0.5)
                tween:Play()
            end
        end
    end
end

I'm trying to make it so every time the success function is called, it tweens the player to the handle, it errors on line 9 which is, TS:Create(HRP, TweenInfo.new(1), {CFrame = CFrame.new(c:FindFirstChild("Handle").CFrame)}), I'm not doing teleportation because of the anti cheat detecting teleportation.

2 comments

0

Is this all the code?

0

Nope, don't want to show the source of the success() function but I don't think that's needed, the problem is on line 9 around the part where I get the handles CFrame.

2 answers

✓ Accepted answer

Problem

You are trying to create a CFrame from a CFrame value.

Description

There is not a constructor that creates a CFrame value from a CFrame value, thus your error. A list of constructors can be found on the CFrame's Roblox API page.

To create a basic CFrame from a Vector position, you can use this:

local ThisIsACFrame = CFrame.new(Vector3.new(0, 0, 0)) -- Creates a CFrame at position 0,0,0

The error was given because Roblox assumed you were trying to use the constructor from the code above but found a CFrame instead of a Vector3 value.

CFrame.new ( Vector3 pos )

Solution

You could create a new CFrame, but in this case it is not necessary. Instead, since you already have a desired CFrame, you could simply set the Tween's goal to:

Code

TS:Create(HRP, TweenInfo.new(1), {CFrame = c:FindFirstChild("Handle").CFrame})

If you have any questions or feel that any part of this answer was unclear, feel free to contact me via Discord (phxntxsmic#2021)

{CFrame = CFrame.new(c:FindFirstChild("Handle").CFrame.p)}

This discussion is preserved as it was. New answers, comments, and votes are closed.