Hello! I’m currently looking into how to get all children with the same name
local function GetChildrenWithSameNames(Directory, TargetName)
local Children = {}
for _, Obj in pairs(Directory:GetChildren()) do
if Obj.Name == TargetName then
table.insert(Children, Obj)
end
end
return Children
end
Haven’t tested it but it should work.
Also, please try it yourself before asking others to make it for you.
I’ll provide the code here as well.
for _, child in ipairs(object:GetChildren()) do
if child.Name == "SinkHit" then
--Perform action.
end
end
for _, child in ipairs(object:GetChildren()) do
if child.Name == "SinkHit" then
local prompt = child:FindFirstChildOfClass("ProximityPrompt")
if prompt then
prompt.Triggered:Connect(function(player)
print(player.Name)
end)
end
end
end
It currently clones depending on how much of the items are in each category. Not sure why.
for _, child in ipairs(workspace:GetChildren()) do
if child.Name == “BowlHit” then
child.ProximityPrompt.Enabled = true
local prompt = child:FindFirstChildOfClass(“ProximityPrompt”)
if prompt then
prompt.Triggered:Connect(function(player)
for _, child in ipairs(workspace:GetChildren()) do
if child.Name == “BowlHit” then
child.ProximityPrompt.Enabled = false
local bowlClone = game.ReplicatedStorage.MisoSoup:Clone()
bowlClone.Name = "Miso Soup"
bowlClone.Parent = game.Players.LocalPlayer.Backpack
bowlClone.Parent = game.Players.LocalPlayer.Character
bm1.Attachment1 = at1
bm1.Attachment0 = workspace:FindFirstChild("SinkHit").Attachment
for _, child in ipairs(workspace:GetChildren()) do
if child.Name == "SinkHit" then
child.ProximityPrompt.Enabled = true
end
end
end
end
end)
end
end
end
this doesn’t seem to work as I thought it would, what I’m trying to do is get children within children, so this same function but going one layer deeper. to create a mantle script