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

How do i check if part named "Touching part" touched hitbox?

I want hitbox that detects if part named "Touching part" Touches it when it does it executes code

Here is what i have so far:

local part = script.Parent
local light = script.Parent.Parent.SpotLight
part.Touched:Connect(function(hit)
	if hit:FindFirstChild("TouchingPart") then
		light.Enabled = false
	end
end)

1 answer

✓ Accepted answer

"FindFirstChild" isn't trying to get the name, its trying to find a child inside of the part that hit it (or "hit") named "TouchingPart". Instead you would compare the two strings by getting the Name property of the part, which will return the name of the part, then compare it inside of a if statement with the string "ToucingPart".

local part = script.Parent


part.Touched:Connect(function(hit)
	if hit.Name == "TouchingPart" then -- Getting the name property of a part will return a string in which you could compare with another in a if statement.
		-- whatever you want
	end
end)

1 comment

0

Thanks

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