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

LookVector is not a valid member of Vector3? (help)

Asked by 2 years ago
Edited 2 years ago

I want this ball to go in front of me, but then it gives me an error saying " LookVector is not a valid member of Vector3 - Server - Script:7"

Any fixes? Thanks.

local ball = game.Workspace.Part
local wastouched = false

ball.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and not wastouched then
        wastouched = true
        ball.CFrame = hit.Parent:FindFirstChild("HumanoidRootPart").CFrame.LookVector * CFrame.new(0, 5, -5)
    end
end)
0
This code is packed with contradictions. Ziffixture 6913 — 2y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

That error does not sound right.

There are 3 issues with line #7:

ball.CFrame = hit.Parent:FindFirstChild("HumanoidRootPart").CFrame.LookVector * CFrame.new(0, 5, -5)

1). You're using Instance:FindFirstChild inappropriately. FindFirstChild has the capacity to return nil, so when intending to use its return result, you must verify said result beforehand:

local X = Y:FindFirstChild("Z")

if X then
    -- Use X
end

2). Vector3 * CFrame is an unsupported operation—see Vector3's available "Math Operations". The error you should have received, "invalid argument #1 (CFrame expected, got Vector3)", will have been risen from this contradiction.

3). After removing * CFrame.new(0, 5, -5), you will make an attempt to assign a Vector3 to a property that expects a CFrame. This cannot be done, and will raise another error.

The code you mean to write is:

X.CFrame = Y.CFrame * CFrame.new(--[[X, Y, Z]])
-- This code aligns the ball's orientation to that of the Y's.

Furthermore, your debounce puts your callback out of commission. It's better to disconnect your RBXScriptConnection so the callback can be properly removed. For more information, see "Handling Events".

0
Thanks, but i want the ball to be in front of me at all times where i am looking. The code you described gives a CFrame relative to another CFrame, i want a position to be relative to where i look so when i first touch the ball it needs to be directly in front of me at all times. TakeItToTheM 0 — 2y
0
Are you going to help? TakeItToTheM 0 — 2y
0
The code above will place the ball in front of the HRP with respect to its current orientation. If you're looking to keep it there, use a WeldConstraint Ziffixture 6913 — 2y
Ad

Answer this question