Hi guys, I have a kill manager which should get each kill part from each map so that the code is not repeated for every part, could you guys help me find out what is wrong with it, it doesn’t print any errors or “touched”
for i,b in ipairs(a) do
for i,v in ipairs(b:GetChildren()) do
for i,x in ipairs(v.Killers:GetChildren()) do
x.Touched:Connect(function(Object)
if Object.Parent:FindFirstChild("Humanoid") then
print("touched")
end
end)
end
end
end
local Maps = game.Workspace.Maps
local Map1 = Maps.Volcano
local Killers = Map1.Killers
for _,model in pairs(Killers:GetChildren()) do
for _,child in pairs(model:GetChildren()) do
child.Touched:Connect(function(object)
if object.Parent:FindFirstChild("Humanoid") then
--do code
end
end)
end
end
From the code you have provided it seems you are checking if players have touched the models, you would need another for loop to check inside every model for parts.
local Maps = game.Workspace.Maps
for _,map in pairs(Maps:GetChildren()) do
for _,child in pairs(map.Killers:GetChildren()) do
for _,descendant in pairs(child:GetChildren()) do
if descendant:IsA("BasePart") then
descendant.Touched:Connect(function(obj)
if obj.Parent:FindFirstChildWhichIsA("Humanoid") then
print("A player has touched the brick!")
end
end)
end
end
end
end
local a = game.Workspace.Maps:GetChildren()
for i,b in ipairs(a) do
for i,v in ipairs(b:GetChildren()) do
for i,x in ipairs(v.Killers:GetChildren()) do
for i,p in ipairs(x.GetChildren()) do
p.Touched:Connect(function(Object)
if Object.Parent:FindFirstChild("Humanoid") then
print("touched")
end
end)
end
end
end
end
In this, p would be the parts inside the models in killer wouldn’t it? It still doesn’t work for some reason
local Maps = game.Workspace.Maps
for _,map in pairs(Maps:GetChildren()) do
for _,child in pairs(map.Killers:GetChildren()) do
for _,descendant in pairs(child:GetChildren()) do
if descendant:IsA("BasePart") then
descendant.Touched:Connect(function(obj)
if obj.Parent:FindFirstChildWhichIsA("Humanoid") then
print("A player has touched the brick!")
end
end)
end
end
end
end
You dont need the first loop, just put maps in the second loop.
local a = game.Workspace.Maps
for i,v in ipairs(a:GetChildren()) do
for i,x in ipairs(v.Killers:GetChildren()) do
for i,p in ipairs(x.GetChildren()) do
p.Touched:Connect(function(Object)
if Object.Parent:FindFirstChild("Humanoid") then
print("touched")
end
end)
end
end
end
for _, Object in pairs(game.Workspace.Maps:GetDescendants()) do
if Object:IsA("BasePart") and Object:FindFirstAncestorWhichIsA("Model") then
Object.Touched:Connect(function()
end)
end
end