The Script thought 'local' is an error. The error message: Syntax error: Expected identifier when parsing expression, got 'local'

Wow… The script says this: syntax error :face_with_raised_eyebrow:
Does anyone have any fixes either it is easy to fix.
Yep. I also found a working script and pasted it in and it did not work. It is underlined with red. the error

Could you paste the full code, it is probably a pasting issue.

Oh. A pasting issue? Oh here is the code: local diceBlock = – dice block
local start = diceBlock.Position:VectorToWorldSpace(0, 5, 0)
local ray = Ray.new(start, diceBlock.Position - start)
local hit = workspace:FindPartOnRayWithWhiteList(ray, {diceBlock}) – so it can’t intersect with other parts

print(hit)
I got this from a Dev Forum post.

3 Likes

You never defined dice block there is just a comment after it which makes the compiler think that the local following it is part of the definition. Define dice block and it should fix the issue.

 local diceBlock = -- dice block
local start = diceBlock.Position:VectorToWorldSpace(0, 5, 0)
local ray = Ray.new(start, diceBlock.Position - start)
local hit = workspace:FindPartOnRayWithWhiteList(ray, {diceBlock}) – so it can’t intersect with other parts

Well there is your issue, you probably didn’t define the path to the block so Lua(u) sees it as local diceBlock = local start = diceBlock.Position:VectorToWorldSpace(0, 5, 0)

Variable declarations are assignments, not expressions, so you’ll have to fill the path out yourself.

By the way :VectorToWorldSpace is a method of CFrame, not Vector3, and it takes a Vector3 object, not 3 numbers.

So the fixed code would be

local diceBlock = game.Workspace:WaitForChild("DiceBlock") -- the name is just an example, change it to the real name of your block
local start = diceBlock.CFrame:VectorToWorldSpace(Vector3.new(0, 5, 0))

local params = RaycastParams.new()
params.FilterDescendantsInstances = { diceBlock }
params.FilterType = Enum.RaycastFilterType.Whitelist

local result = game.Workspace:Raycast(start, diceBlock.Position - start, params)

if result then
    local hit = result.Instance
    print(hit)
end

The old raycasting API is deprecated (WorldRoot:FindPartOnRay, etc), use the new one instead, which I showed.

1 Like

Thanks you! I thought the script was fine and not old. So I’ll use it!
It worked no bugs! But where do I place it?