trying to make a touched function that before it prints "hi" it checks if 'hit' has a child named Break, but nothing works. how can i fix this problem? someone? Dora? Boots? Diego??
script.Parent.Touched:Connect(function(hit) if hit:FindFirstChild("Break") then print("hi") end end)
You could do this:
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Break") then print("hi") end end)
I normally use this method as it is much more clear:
local part = game.Workspace.Break -- Define where the part is local function OnTouched() -- Define a function that prints hi print("hi") end part.Touched:Connect(OnTouched) -- Fires the function when part is touched