Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year ago

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

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

"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)
0
Thanks kubapro213748 -13 — 1y
Ad

Answer this question