How do I fix this settings gui script?

So I have this settings UI that has these options as seen in the picture:

How the UI looks like in explorer:
Screenshot_1

Now inside the “Settings” local script I have this code, before I send the code I want to clarify that I want the settings to be kinda like a toggle on and off button, no need for any fancy stuff just an image change is more than enough, but the code itself doesn’t seem to be working that well as I don’t have much of an idea about some stuff written in it, I have it so that the white toggle button is considered “off” and the black toggle button is considered “on”, now the buttons do the following:

  • Disable Collisions (currently the text label only says Collisions):
    OFF> players can’t collide with each other.
    ON> players can collide with each other.

  • Hide Players:
    OFF> player can see other players.
    ON> player can’t see other players.

  • Hide Koins:
    OFF> a specific GUI (which consists of a text label) appears normally on the screen.
    ON> the specific GUI doesn’t appear anymore.

  • HD Graphics:
    OFF> graphics look lower quality.
    ON> graphics look higher quality.

  • Hide UI:
    OFF> doesn’t hide a specific frame (which consists of ImageButtons).
    ON> hides the specific frame.

  • Streamer Mode:
    OFF> doesn’t hide the ROBLOX core GUI (leaderboard and players list ONLY).
    ON> hides the ROBLOX core GUI (leaderboard and players list ONLY).

Here is the current local script that I have which doesn’t seem to be fully working, some parts work and some parts kind of break/glitch sometimes, and some parts don’t work at all, I’m not very sure:

local Players = game:GetService("Players") -- grabbing ALL Players
local Player = game.Players.LocalPlayer -- grabbing Local Player
local visible = true
local hiding = false

local cache = {} -- array of cache
local shadows = {} -- array of shadows
local plrs = {} -- array of plrs

local CollisionsButton = script.Parent.CollisionsButton
local MuteMusicButton = script.Parent.MuteMusicButton
local HidePlayersButton = script.Parent.HidePlayersButton
local HideKoinsButton = script.Parent.HideKoinsButton
local HDGraphicsButton = script.Parent.HDGraphicsButton
local HideUIButton = script.Parent.HideUIButton
local StreamerModeButton = script.Parent.StreamerModeButton

local PhysicsService = game:GetService("PhysicsService")

--[[ HIDE PLAYERS FUNCTION ]] -- 

HidePlayersButton.MouseButton1Click:Connect(function() -- People Button

	if not hiding then
		HidePlayersButton.Image = "rbxassetid://10760955733"
		hiding = true
		local player = game.Players:GetChildren()
		for i = 1,#player do
			if player[i].Name ~= Player.Name then
				table.insert(plrs,workspace[player[i].Name])
			end
		end
		for i = 1,#plrs do
			plrs[i].Parent = nil
		end
	elseif hiding then
		HidePlayersButton.Image = "rbxassetid://10760955841"
		hiding = false
		for i = 1,#plrs do
			plrs[i].Parent = workspace
		end
		plrs = {}
	end

end)

--[[ HD GRAPHICS FUNCTION ]] -- 

for i, part in pairs(workspace:GetDescendants()) do
	if part:IsA("BasePart") then
		cache[part] = part.Material
		shadows[part] = part.CastShadow
	end
end

HDGraphicsButton.MouseButton1Click:Connect(function() -- Graphic Button

	-- Set the visible to the opposite of what it was
	visible = not visible

	if visible then
		for _, part in pairs(workspace:GetDescendants()) do
			if part:IsA("BasePart") and cache[part] ~= nil and shadows[part] ~= nil then
				part.Material = Enum.Material.Plastic
				part.CastShadow = false
			end
		end
		HDGraphicsButton.Image = "rbxassetid://10760955733"
	else
		for i, part in pairs(workspace:GetDescendants()) do
			if part:IsA("BasePart") and cache[part] ~= nil and shadows[part] ~= nil then
				part.Material = cache[part]
				part.CastShadow = shadows[part]
			end
		end
		HDGraphicsButton.Image = "rbxassetid://10760955841"
	end
end)

--[[ HIDE UI FUNCTION ]]

HideUIButton.MouseButton1Click:Connect(function() 
	
	if not hiding then
		script.Parent.Parent.Bar.Visible = false
		script.Parent.Parent.Parent.InviteFriendsGui.IconButton.Visible = false
		HideUIButton.Image = "rbxassetid://10760955733"
		
	elseif hiding then
		
		script.Parent.Parent.Bar.Visible = true
		script.Parent.Parent.Parent.InviteFriendsGui.IconButton.Visible = true
		HideUIButton.Image = "rbxassetid://10760955841"
		
	end

end)

--[[ STREAMER MODE FUNCTION ]]

StreamerModeButton.MouseButton1Click:Connect(function()
	
	if not hiding then
		
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
		StreamerModeButton.Image = "rbxassetid://10760955733"
		
	elseif hiding then
		
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
		StreamerModeButton.Image = "rbxassetid://10760955841"
		
	end
	
end)

--[[ HIDE KOINS FUNCTION ]]

HideKoinsButton.MouseButton1Click:Connect(function() 

	if not hiding then
		script.Parent.Parent.Parent.KoinsGui.Cash.Visible = false
		HideKoinsButton.Image = "rbxassetid://10760955733"

	elseif hiding then

		script.Parent.Parent.Parent.KoinsGui.Cash.Visible = true
		HideKoinsButton.Image = "rbxassetid://10760955841"

	end

end)

--[[ COLLISIONS FUNCTION ]] -- 

CollisionsButton.MouseButton1Click:Connect(function()
	
	if not hiding then
		
		CollisionsButton.Image = "rbxassetid://10760955733"
		
		PhysicsService:CollisionGroupSetCollidable("Players", "Players", false)
	
		game. Players.PlayerAdded:Connect(function(plr)
			plr.CharacterAdded:Connect(function(char)
				repeat wait (1) until char:WaitForChild("Humanoid")

				for _, characterPart in pairs (char:GetChildren()) do
					if characterPart:IsA("BasePart") then
						PhysicsService:SetPartCollisionGroup(characterPart, "Players")
					end
				end
			end)
		end)
		
	elseif hiding then
		
		CollisionsButton.Image = "rbxassetid://10760955841"
		
		PhysicsService:CollisionGroupSetCollidable("Players", "Players", true)

		game. Players.PlayerAdded:Connect(function(plr)
			plr.CharacterAdded:Connect(function(char)
				repeat wait (1) until char:WaitForChild("Humanoid")

				for _, characterPart in pairs (char:GetChildren()) do
					if characterPart:IsA("BasePart") then
						PhysicsService:SetPartCollisionGroup(characterPart, "Players")
					end
				end
			end)
		end)
		
	end
	
end)

-Please explain thoroughly as I am not very good at this :cry:

Don’t know what’s happening in the replies, but could you send a file with the gui? It’s way easier to script it if we can also test it in the same place.

2 Likes

Yes, sure thing!
Here is the file:
settingsgui.rbxl (51.7 KB)

I have no idea what’s happening in the replies lol sorry.

you should loop through all buttons instead

1 Like

Do you mind explaining more thoroughly, please?

you could have a attribute in buttons that say what they do, then a module that does the actions.

ill send a example for what i did in my game

1 Like

image

1 Like

then in the module

1 Like

then to get all buttons do

for i,v in pairs(SettingsFrame:GetChildren())
if v:IsA(“ImageButton”) then
– do stuff

end
end

1 Like