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

Unable to cast Raycast Result to Ray?

Asked by
Nuqz 0
2 years ago
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local cloudsFolder = workspace:WaitForChild("clouds")

local head = character:WaitForChild("Head")
local leftFoot = character:WaitForChild("LeftFoot")
local rightFoot = character:WaitForChild("RightFoot")
local newRay = workspace:Raycast(head.Position, Vector3.new(0, 10, 0))
local newRay2 = workspace:Raycast(rightFoot.Position, Vector3.new(0, -10, 0))
local newRay3 = workspace:Raycast(leftFoot.Position, Vector3.new(0, -10, 0))

humanoid.StateChanged:connect(function()
    local hit, position = workspace:FindPartOnRayWithWhitelist(newRay, cloudsFolder:GetChildren())
    local hit2, postion2 = workspace:FindPartOnRayWithWhitelist(newRay2, cloudsFolder:GetChildren())
    local hit3, position3 = workspace:FindPartOnRayWithWhitelist(newRay3, cloudsFolder:GetChildren())

    if hit then
        hit.CanCollide = false
    end

    if hit2 then
        hit2.CanCollide = true
    end

    if hit3 then
        hit3.CanCollide = true
    end
end)

At line 15 which is local hit, position = workspace:FindPartOnRayWithWhitelist(newRay, cloudsFolder:GetChildren())

cloudsFolder is a folder with no subfolders containing cloud mesh parts "Unable to cast Raycast Result to Ray"

0
You cant whitelist the Children of a parent if its not in a table. try doing {cloudsFolder:GetChildren()} with brackets! Hi_People1133 218 — 2y
0
I tried, didnt work same error. I found another way to do this with updated versions (raycastparams and such) but I have no idea why this old version still doesn't work? Nuqz 0 — 2y

Answer this question