#I am having a problem with assigning a table value to a raycastparams FilterDescendantsInstances

1 messages · Page 1 of 1 (latest)

analog hinge
#

The raycast params keeps returning an empty table even tho i set it (This is a module script)

#

This is the code


local params = RaycastParams.new
params().FilterType = Enum.RaycastFilterType.Exclude
params().RespectCanCollide = true



local plrs = game:GetService("Players")

function getallacessories(plr)
    local chs = {}
    table.insert(chs,plr.Character)
    for _, x in pairs(plrs:GetChildren()) do
        local ch = x.Character


        for _, c in pairs(ch:GetChildren()) do
            if c:IsA("Accessory") or c:IsA("Tool") then
                table.insert(chs, c)
            end
        end



    end
    
    for _, x in pairs(workspace:GetChildren()) do
        if x:IsA("Model") and x:FindFirstChildOfClass("Humanoid") then
        local ch = x


        for _, c in pairs(ch:GetChildren()) do
            if c:IsA("Accessory") or c:IsA("Tool") then
                table.insert(chs, c)
            end
        end
        
        
        end
    end
    
    --print(chs)
    return chs
end


function raycast(plr,barrel,mouse)
    local dscts = getallacessories(plr)
    print(dscts, " ----- descenatnts") --(Returns table of players and rigs)
    params().FilterDescendantsInstances = dscts
    print(params().FilterDescendantsInstances) -- (This does not return anything other than an empty table)
    local dir = mouse - barrel.Position 
    local ray = workspace:Raycast(barrel.Position, dir, params())

    return ray
end
snow patrol
#

-- Maybe This will help you ?
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local chs = {}
table.insert(chs, character)
for i, c in pairs(character:GetChildren()) do
print(c)
if c:IsA("Accessory") or c:IsA("Tool") then
table.insert(chs, c)
print(chs)
if c:IsA("Accessory") then
local dscts = c
print(dscts)
end

        end
    end    
    for n, m in pairs(workspace:GetChildren()) do
        if m:IsA("Model") then
            local x = m:FindFirstChildOfClass("Humanoid")
            print(x)
            table.insert(chs, x)
            print(chs)
        end
    end
end)                

end)

-- x is the humanoid
-- c is the accessory or tool
-- dscts is the description of the accessory or tool - same as c
-- character is the player's character
-- chs is the table that is now holding all accessories, tools, the character and the humanoid

twin jasper
snow patrol
#

oops typo - c is an accessory, but if you want to make the variable dscts then just take out the extra if statements and only set the variable as local dscts = c, that way both accessories and tools are now added. If you want to decipher them individually then you can rename each different to separate them out.

#

-- Maybe This will help you ?
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local chs = {}
table.insert(chs, character)
for i, c in pairs(character:GetChildren()) do
print(c)
if c:IsA("Accessory") or c:IsA("Tool") then
table.insert(chs, c)
print(chs)
local dscts = c
--if c:IsA("Accessory") then
-- local dscts = c
-- print(dscts)
--end
--if c:IsA("Tool") then
-- local dscts = c
-- print(dscts)
--end
print(dscts)
end
end
for n, m in pairs(workspace:GetChildren()) do
if m:IsA("Model") then
local x = m:FindFirstChildOfClass("Humanoid")
print(x)
table.insert(chs, x)
print(chs)
end
end
end)
end)

-- x is the humanoid
-- c is the accessory or tool
-- dscts is the description of the accessory or tool - same as c
-- character is the player's character
-- chs is the table that is now holding all accessories, tools, the character and the humanoid

analog hinge
analog hinge
#

My code works now

snow patrol
#

It looked to me like you are not getting the character in the beginning correctly inside of your function: function getallacessories(plr) because it is giving me an error.

karmic yachtBOT
#

studio** You are now Level 2! **studio

analog hinge
snow patrol
#

ahh ok

analog hinge
#

Thank you for the help too

snow patrol
#

Sure, it keeps me on my toes, even if i don't always know exactly what your setup is, so my trouble shooting may not be perfectly always helpful. I try though, lol.

analog hinge
#

I need to provide more context next time i think