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

Why does the text label turn on once the player is in the region3 but does not go if player left?

Asked by 3 years ago

I know there must be some silly error I have in this code so can someone please help me identify it?

local talkAreas = game.Workspace:WaitForChild("TalkRegions")

local Found = false

while wait(1) do
    for i, v in pairs(talkAreas:GetChildren()) do
        found = false
        local region = Region3.new(v.Position - (v.Size / 2), v.Position + (v.Size / 2))
        local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())

        for _, part in pairs(parts) do
            if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
                print("PlayerIsThere")
                Found = true
                break
            else
                Found = false
                print("PlayerNotFoundInRegionUBot")
            end
        end

        if Found == true then
            if script.Parent.Talk.TalkIndication.Visible == false then
                script.Parent.Talk.TalkIndication.Visible = true
                break
            end
        else
            print("NahFam")
            script.Parent.Talk.TalkIndication.Visible = false   

        end
    end
end

Answer this question