I am trying to disable movement when a gui is open and enable it when the gui is closed, this is what I have but it doesn't work.


game:WaitForChild("Players").PlayerAdded:Connect(function(player)
	game.StarterGui.MapOpenClose.ImageButton.MouseButton1Click:Connect(function()
		player.CharacterAppearanceLoaded:Connect(function(character) 
if game.StarterGui.Map.Frame.Visible == true then 

	   character.Humanoid.WalkSpeed = 0 
end
		end)
	end)
	

game:WaitForChild("Players").PlayerAdded:Connect(function(player)
	game.StarterGui.MapOpenClose.ImageButton.MouseButton1Click:Connect(function()
if game.StarterGui.Map.Frame.Visible == false then 
player.CharacterAppearanceLoaded:Connect(function(character) 
	character.Humanoid.WalkSpeed = 30


end)
end
	end)
end)
end)