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)
"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)