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

How do I make this "not hit" function work properly?

Asked by 7 years ago

I made this script inside a part, that when touched, it becomes invisible, and when not touched, it appears again.

When I touch it, it turns invisible, but it stays like that even when I'm not touching it.

script.Parent.Touched:connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid")
    if H then
        script.Parent.Transparency = 1
    elseif not H then
        script.Parent.Transparency = 0
    end 
end)

1 answer

Log in to vote
0
Answered by 7 years ago

Use the TouchEnded event.

script.Parent.TouchEnded:connect(funtcion(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid")
        if H and script.Parent.Transparency == 1 then
            repeat wait() until H 
            script.Parent.Transparency = 0
        elseif not H then
            script.Parent.Transparency = 1
    end
end)
0
Perfect! I didn't know such a function existed! CaptaiinNoob 52 — 7y
Ad

Answer this question