local gold = workspace:WaitForChild('gold') gold.Touched:connect(function(hit) if hit.Parent:FindFirstChild('Humanoid') then print('hi') end end)
i need help making it so if any part named 'gold' get touched, it prints hi and not just that one part, which is what its doing.
you can use a generic for loop which literates through a table, in which :GetChildren()
returns.
local gold = workspace:GetChildren() -- returns a table or a array for _,v in pairs(gold) do -- v is the value its currently looping over local lower = string.lower(v.Name) if lower == "gold" then -- checks if the name is "gold" v.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then print("hi") end end) end end