#I am having a problem with assigning a table value to a raycastparams FilterDescendantsInstances
1 messages · Page 1 of 1 (latest)
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
-- 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
Hey Dania!
- Are you sure you're** assigning your raycastParams** correctly? The setup you have here is actually creating a new raycast parameter instance every time you try to set its property.
To correctly create a raycast params, assign raycastParams.new**()** in your initial params variable.
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
Alright so i found the issue thanks to this
Thank you very much ClockedDev
My code works now
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.
** You are now Level 2! **
This was just a snippet of the code i'm getting "plr" from a local script
ahh ok
Thank you for the help too
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.
I need to provide more context next time i think