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

bad argument #1 to 'new' (Vector3 expected, got CFrame)? [Help]

Asked by
C1RAXY 81
5 years ago

Hi.. Mi problem is trying to change the HRP CFrame tweening it to a target but I get this error in the console.

Workspace.C1RAXY.LocalScript:15: bad argument #1 to 'new' (Vector3 expected, got CFrame)

and the local script (In a GUI Button) I made is:

local TweenService = game:GetService("TweenService")
local Character = game.Players.LocalPlayer.Character.HumanoidRootPart
local target = workspace.Target.Position

local Info = {
3,                           
Enum.EasingStyle.Bounce,     
Enum.EasingDirection.Out,    
1,                           
false,                       
1                           
}

local Goals = {
    CFrame.new(target.X,target.Y,target.Z)
} 

local tween = TweenService:Create(Character,Info,Goals)

script.Parent.MouseButton1Click:Connect(function()
wait(1)
tween:Play()
end)

I tried changing the target property, like this:

 local target = workspace.Target.CFrame

I tried changing the Character property, like this:

 local Character = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame

I tried changing the Goals like this :

local Goals = {
    Vector3.new(target.X,target.Y,target.Z)
} 

Im pretty noob ik :( but yeah... If anyone has an answer I will be glad to read it.

Thanks.

1 answer

Log in to vote
1
Answered by 5 years ago

There are a lot of small errors with this code which is probably what is causing your confusion.

The first error is how you are constructing the TweenInfo roblox data type. In your code you are simply creating a table and assigning it to the variable.

To construct this roblox data type you would follow the same process as you have done with CFrame.new().

local Info = TweenInfo.new(
    3,                           
    Enum.EasingStyle.Bounce,     
    Enum.EasingDirection.Out,    
    1,                           
    false,                       
    1                           
)

I am unsure how the error you have posted relates to this code as CFrame.new(target.X,target.Y,target.Z) is valid for both CFrame and Vector3 due to them both having X,Y,X properties.

But I can say that the way the Goals dictionary is being set would give an error as you have not included the propertie name you want to be tweened. see here for more info about what this dictionary accepts.

The dictionary format in your case is probably.

-- name of [propertie] = goal
local Goals = {
    CFrame = CFrame.new(target.X,target.Y,target.Z)
} 

Better still you can simply use local Goals = {CFrame = target} if target is a CFrame.

Hope this helps.

0
Thx for the Answer. C1RAXY 81 — 5y
Ad

Answer this question