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

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

Asked by
pz_pi 2
3 years ago

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.

0
Is this all the code? MarkedTomato 810 — 3y
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. pz_pi 2 — 3y

2 answers

Log in to vote
0
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

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)

Ad
Log in to vote
0
Answered by 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

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

Answer this question