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

Umm. Can someone help me with this? I can't seems to fix this Touched event?????????

function hit()
	print("got it")
	if hit.Parent:FindFirstChild("Humanoid") then
		print("ayy")
	end
end	
script.Parent.Lighten.Touched:Connect(hit)
script.Parent.Lighten2.Touched:Connect(hit)

It's in a script which has other things too It doesn't print anything too.

1 answer

✓ Accepted answer

Here's a proper example of how to use .Touched

--we can do this one of two ways:

local part = workspace.Part --for example

part.Touched:Connect(function(PartThatTouched)
	if PartThatTouched.Parent:FindFirstChild("Humanoid") then
		print(PartThatTouched.Name)
	end
end)

--or we can use a named function

function OnTouch(PartThatTouched)
	if PartThatTouched.Parent:FindFirstChild("Humanoid") then
		print(PartThatTouched.Name)
	end
end

part.Touched:Connect(OnTouch)

2 comments

0

fail, the humanoid won't be inside the part

0

my bad xd

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