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