local UserInputService = game:GetService(“UserInputService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local playerGui = player:WaitForChild(“PlayerGui”)
local optionsGui = playerGui:WaitForChild(“OptionsGui”)
local optionsFrame = optionsGui:WaitForChild(“OptionsFrame”)
local keyInputBox = optionsFrame:WaitForChild(“KeyInputBox”)
local confirmButton = optionsFrame:WaitForChild(“ConfirmButton”)
local closeButton = optionsFrame:WaitForChild(“CloseButton”)
local openOptionsButton = optionsGui:WaitForChild(“OpenOptionsButton”)
local toggleKey = Enum.KeyCode.F
local visibleTransparency = 0
local hiddenTransparency = 0.7
local showGroupA = true
local toggleEvent = ReplicatedStorage:FindFirstChild(“ToggleGroupCollision”)
– dynamically get ALL groups relevant to toggling
local function getGroups()
local groupA = workspace:FindFirstChild(“GroupA”)
local groupB = workspace:FindFirstChild(“GroupB”)
local course2Parts = workspace:FindFirstChild(“Course2Parts”)
local groupA2 = nil
local groupB2 = nil
if course2Parts then
groupA2 = course2Parts:FindFirstChild("GroupA2")
groupB2 = course2Parts:FindFirstChild("GroupB2")
end
return groupA, groupB, groupA2, groupB2
end
local function setGroupVisibility(group, visible)
if not group then return end
for _, part in ipairs(group:GetDescendants()) do
if part:IsA(“BasePart”) then
part.Transparency = visible and visibleTransparency or hiddenTransparency
part.CanCollide = visible
end
end
end
local function updateVisibility()
local groupA, groupB, groupA2, groupB2 = getGroups()
setGroupVisibility(groupA, showGroupA)
setGroupVisibility(groupB, not showGroupA)
setGroupVisibility(groupA2, showGroupA)
setGroupVisibility(groupB2, not showGroupA)
end
local function toggleGroups()
showGroupA = not showGroupA
updateVisibility()
if toggleEvent then
toggleEvent:FireServer(showGroupA)
end
end
– call this function after teleport or map load to refresh groups visibility properly
local function refreshGroups()
updateVisibility()
end
– initialize on script start
updateVisibility()
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == toggleKey then
toggleGroups()
end
end)
openOptionsButton.MouseButton1Click:Connect(function()
optionsFrame.Visible = true
end)
closeButton.MouseButton1Click:Connect(function()
optionsFrame.Visible = false
end)
confirmButton.MouseButton1Click:Connect(function()
local text = keyInputBox.Text:upper()
if Enum.KeyCode[text] then
toggleKey = Enum.KeyCode[text]
print(“Toggle key changed to:”, text)
keyInputBox.Text = “”
else
print(“Invalid key:”, text)
keyInputBox.Text = “”
end
end)
optionsFrame.Visible = false
– expose refreshGroups for external calls, e.g., from teleport script:
_G.RefreshFadeToggle = refreshGroups