Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Beginner] how come my part wont print "hi" when touched?

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)

4 comments

0

is break a child of the part?

0

no its a child of whatever's touching the part

1

You might have to do hit.Parent:FindFirstChild because you want to check a model right?

0

Could you take a picture of your explorer?

1 answer

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

2 comments

0

The part has to touch it, not you. and if it is touching it, check if Break is a child of the object which hit it

0

part is inside whatever's touching the part with the touched function

This discussion is preserved as it was. New answers, comments, and votes are closed.