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

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

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)

1 comment

0

This code is packed with contradictions.

1 answer

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".

3 comments

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.

0

Are you going to help?

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

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