Help with touch highlight

So, I’m trying to make it so when you touch an object, it will highlight another. It works, it just doesn’t disable.

Here is my script.

local door = game.Workspace.DoorHighlight
local plrs = game:GetService("Players")

while wait(0.1) do
    door.Touched:Connect(function(hit)
        local Highlight1 = Instance.new("Highlight")
        Highlight1.DepthMode = Enum.HighlightDepthMode.Occluded
        Highlight1.FillColor = Color3.fromRGB(230, 230, 230)
        Highlight1.FillTransparency = .75
        Highlight1.Adornee = door.Parent.CampingCabin.Door.DoorPart.Part2
        Highlight1.Parent = plrs.LocalPlayer:WaitForChild("PlayerGui")
        local Highlight2 = Instance.new("Highlight")
        Highlight2.DepthMode = Enum.HighlightDepthMode.Occluded
        Highlight2.FillColor = Color3.fromRGB(230, 230, 230)
        Highlight2.FillTransparency = .75
        Highlight2.Adornee = door.Parent.CampingCabin.Door.DoorPart.Part3
        Highlight2.Parent = plrs.LocalPlayer:WaitForChild("PlayerGui")
        Highlight1.Enabled = false
        Highlight2.Enabled = false
        if hit.Parent == plrs.LocalPlayer.Character then
            Highlight1.Enabled = true
            Highlight2.Enabled = true
        else
            Highlight1.Enabled = false
            Highlight2.Enabled = false
        end
    end)
end
1 Like

Try this and add a boolean at the top called “canTouch” and set its value to true

        if hit.Parent == plrs.LocalPlayer.Character and canTouch == true then
            canTouch = false
            Highlight1.Enabled = true
            Highlight2.Enabled = true
        elseif hit.Parent == plrs.LocalPlayer.Character and canTouch == false then
            canTouch = true
            Highlight1.Enabled = false
            Highlight2.Enabled = false
        end
    end)
end

Now, it only highlights part3, and not part2. And the highlight still doesn’t go away.