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

I need help, it just says "Unable to cast value to Objects". But why?

Asked by 3 years ago
Edited by appxritixn 3 years ago
local part = script.Parent
local badpart = game.Workspace.shit
while true do
    wait(1) 
    raypar = RaycastParams.new()
    raypar.FilterDescendantsInstances = workspace.shit
    raypar.FilterType = Enum.RaycastFilterType.Blacklist
    local origin = part.Position
    local direction = part.CFrame.LookVector * 100
    local result = workspace:Raycast(origin, direction, raypar)
    if result then
        print(result.Instance.Name)
    end
    if not result  then
        print("nothing")
    end
end

0
Put your code in a code block for it to be easier to read and don't put inappropriate words in your code MarkedTomato 810 — 3y
0
Formatted the code appxritixn 2235 — 3y
1
Whats the exact error? Which line of code fails? AlexanderYar 788 — 3y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Problem:

You forgot to introduce the curly braces, which look like this {} on line 6 where it says workspace.Part.

The reason it didn't work is because the script thinks that you're trying to set the value, which in this case is raypart to an object, which is the part, remember that FilteringStrings are arrays.(tables)

Solution:

Add the curly braces on line 06.

Fixed Code:

local part = script.Parent
local badpart = game.Workspace.shit
while true do
    wait(1) 
    raypar = RaycastParams.new()
    raypar.FilterDescendantsInstances = {workspace.shit}
    raypar.FilterType = Enum.RaycastFilterType.Blacklist
    local origin = part.Position
    local direction = part.CFrame.LookVector * 100
    local result = workspace:Raycast(origin, direction, raypar)
    if result then
        print(result.Instance.Name)
    end
    if not result  then
        print("nothing")
    end
end

Read the developer forums on :RayCastParams

Resources:

RaycastParams Screenshot- RobloxDeveloperHub

RaycastParams

0
This is off-topic but don't name your stuff inappropriately. JesseSong 3916 — 3y
Ad

Answer this question