Enable/Disable Surface GUI

Hello! Im trying to figure out how a player can enable and disable the Marker in a settings menu does anyone know how to fix this issue possible to edit the script below since it doesnt quite work lol

Player = game.Players.LocalPlayer
Button = script.Parent
Marker = game.Workspace.WorkspaceMaps:FindFirstChild("Hitbox").Marker

script.Parent.MouseButton1Click:Connect(function()
	
	if Marker == true then
		Marker.Enabled = false
		
	elseif Marker == false then
		Marker.Enabled = true
	end
end)

The line where you defined “Marker” is incorrect. It should be:

local Marker = game.Workspace.WorkspaceMaps.LavaCavern.Buttons.Button1.Hitbox.Marker
1 Like

Why are you saying if Marker == true? isn’t it Marker.Enabled == true?
Ofcourse do not forget to change where the Marker is located.
so:

Player = game.Players.LocalPlayer
Button = script.Parent
Marker = game.Workspace.WorkspaceMaps:FindFirstChild("Hitbox").Marker

script.Parent.MouseButton1Click:Connect(function()
	
	if Marker.Enabled == true then
		Marker.Enabled = false
		
	elseif Marker.Enabled == false then
		Marker.Enabled = true
	end
end)

there are multiple buttons and maps so I can define the map and button as 1

FindFirstChild only works for the direct children of it, so it will return nil. You could do :FindFirstDescendant(), but since there are multiple maps you don’t know which marker it will return.

The script is running server side, LocalPlayer doesn’t exist.