Script doesn't work

what this script is meant to do is when the main menu frame is visible clickdetectors’s Max activation distance are set to infinity, or else their Max activation dist will be set to 32

script:

local mainMenuFrame = script.Parent


local function updateClickDetectors()
    local distance = mainMenuFrame.Visible and math.huge or 32  -- Set distance based on visibility
    for _, part in pairs(workspace:GetDescendants()) do
        if part:IsA("ClickDetector") then
            part.MaxActivationDistance = distance
        end
    end
end


updateClickDetectors()


mainMenuFrame:GetPropertyChangedSignal("Visible"):Connect(updateClickDetectors)
2 Likes

Is this a script or local script and where is it placed?
I added a few prints to help diagnose the issue, try this

print("hello world")
local mainMenuFrame = script.Parent

local x = 1
local function updateClickDetectors()
    print("function called", x)
    x += 1
    local distance = mainMenuFrame.Visible and math.huge or 32  -- Set distance based on visibility
print("distance is", distance)
    for _, part in pairs(workspace:GetDescendants()) do
        if part:IsA("ClickDetector") then
            part.MaxActivationDistance = distance
            print("click detector found:", part.Name)
        end
    end
end


updateClickDetectors()


mainMenuFrame:GetPropertyChangedSignal("Visible"):Connect(updateClickDetectors)
1 Like

its a local script and its the child of the main menu frame

What part doesn’t work for you?
It works perfectly for me

rlly? it doesn’t work for me tho ig i will manipulate the camera cframe

1 Like

Is there any gui elements between the camera and parts with click detectors which might be sinking the mouse input?

1 Like

no there isnt
111111111111111111111111111111

Hold on, which gui’s visibility are you changing? And are you changing it via client or server? You are supposed to change the visibility of the frame in the player gui

Yeah, I fixed it by manipulating the camera’s position. I’ll close the topic. Thank you!